“Skrip peluru persatuan” Kode Jawaban

Skrip peluru persatuan

    // You need a Firepoint (where the bullet comes from)
    // You need a BulletPrefab to generate a bullet at the Firepoint 
    public Transform FirePoint;
    public GameObject BulletPrefab;
    
    //Decides how fast the bullet shoots
    public float bulletForce = 20f;

    void Update()
    //If the input key is activated then returns the following
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Shoot();
        }
    }

    void Shoot()
    {
        GameObject bullet = Instantiate(BulletPrefab, FirePoint.position, FirePoint.rotation);
        Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
        rb.AddForce(FirePoint.up * bulletForce, ForceMode2D.Impulse);
	}
ChoukoIsBad

Skrip peluru persatuan


public class BulletType : MonoBehaviour
{
    // Protected is less stric than private, more stric than public
    // Protected variables only accesible to this class and its child.
    protected string name;
    protected int bulletDamage;
    protected int bulletSpeed;

    protected virtual void Start()
    {

    }

    // Virtual means you can override this method in child classes
    protected virtual void Damage() { }

    public virtual void PlaySound() { }

    protected virtual void ShowEffect() { }
}

Poor Pigeon

Jawaban yang mirip dengan “Skrip peluru persatuan”

Pertanyaan yang mirip dengan “Skrip peluru persatuan”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya