ショットガンを撃った場合の表現を補強


銃口から火花を出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotBullet : MonoBehaviour {
    public GameObject bulletPrefab;
    public AudioClip shotSound;
    public AudioClip reloadSound;
    public float shotSpeed;
    public int shotCount = 30;
    private float shotInterval;
    // ★火花を出す
    public GameObject effectPrefab;
	void Update () {
        if(Input.GetKey(KeyCode.Mouse0)){
            shotInterval += 1;
            if(shotInterval % 5 == 0 && shotCount > 0){
                shotCount -= 1;
                GameObject bullet = (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.Euler(transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
                Rigidbody bulletRb = bullet.GetComponent<Rigidbody>();
                bulletRb.AddForce(transform.forward * shotSpeed);
                Destroy(bullet, 3.0f);
                AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position);
                // ★火花を出す
                GameObject effect = (GameObject)Instantiate(effectPrefab, transform.position, Quaternion.identity);
                Destroy(effect, 0.1f);
            }
        } else if(Input.GetKeyDown(KeyCode.R)){
            shotCount = 30;
            AudioSource.PlayClipAtPoint(reloadSound, Camera.main.transform.position);
        }
	}
}



弾が着弾した場所に火花を出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyBullet : MonoBehaviour {
    public GameObject effectPrefab;
    void OnCollisionEnter(Collision other){
        if(other.gameObject.tag == "Bullet"){
            Destroy(other.gameObject);
            foreach(ContactPoint contactPoint in other.contacts){
                GameObject effect = (GameObject)Instantiate(effectPrefab, (Vector3)contactPoint.point, Quaternion.identity);
                Destroy(effect, 0.2f);
            }
        }
    }
}
EscapeCombat
他のコースを見る

銃口から火花を出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShotBullet : MonoBehaviour {
    public GameObject bulletPrefab;
    public AudioClip shotSound;
    public AudioClip reloadSound;
    public float shotSpeed;
    public int shotCount = 30;
    private float shotInterval;
    // ★火花を出す
    public GameObject effectPrefab;
	void Update () {
        if(Input.GetKey(KeyCode.Mouse0)){
            shotInterval += 1;
            if(shotInterval % 5 == 0 && shotCount > 0){
                shotCount -= 1;
                GameObject bullet = (GameObject)Instantiate(bulletPrefab, transform.position, Quaternion.Euler(transform.parent.eulerAngles.x, transform.parent.eulerAngles.y, 0));
                Rigidbody bulletRb = bullet.GetComponent<Rigidbody>();
                bulletRb.AddForce(transform.forward * shotSpeed);
                Destroy(bullet, 3.0f);
                AudioSource.PlayClipAtPoint(shotSound, Camera.main.transform.position);
                // ★火花を出す
                GameObject effect = (GameObject)Instantiate(effectPrefab, transform.position, Quaternion.identity);
                Destroy(effect, 0.1f);
            }
        } else if(Input.GetKeyDown(KeyCode.R)){
            shotCount = 30;
            AudioSource.PlayClipAtPoint(reloadSound, Camera.main.transform.position);
        }
	}
}



弾が着弾した場所に火花を出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyBullet : MonoBehaviour {
    public GameObject effectPrefab;
    void OnCollisionEnter(Collision other){
        if(other.gameObject.tag == "Bullet"){
            Destroy(other.gameObject);
            foreach(ContactPoint contactPoint in other.contacts){
                GameObject effect = (GameObject)Instantiate(effectPrefab, (Vector3)contactPoint.point, Quaternion.identity);
                Destroy(effect, 0.2f);
            }
        }
    }
}
ショットガンを撃った場合の表現を補強