“Skrypt Bullet Unity” Kod odpowiedzi

Skrypt Bullet Unity

    // 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

Skrypt Bullet Unity


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

Odpowiedzi podobne do “Skrypt Bullet Unity”

Pytania podobne do “Skrypt Bullet Unity”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu