コード例 #1
0
 public virtual void Fire(Vector3 direction)
 {
     Invoke(nameof(End), Life);
     transform.LookAt(transform.position + direction);
     Velocity = Speed * direction;
     OnFired?.Invoke(this, direction);
 }
コード例 #2
0
    void triggerFire()
    {
        var force = -controller.target.dir.normalized * bulletVelocity;

        var nObj = GameObject.Instantiate(bullet);

        if (fireStart == null)
        {
            nObj.transform.position = this.transform.position;
            nObj.transform.rotation = this.transform.rotation;
        }
        else
        {
            nObj.transform.position = fireStart.transform.position;
            nObj.transform.rotation = fireStart.transform.rotation;
        }

        nObj.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse);

        audioSource.PlayOneShot(fireSound);

        OnFired?.Invoke(this, new EventArgs());
    }
コード例 #3
0
 public void EventFired()
 {
     OnFired?.Invoke();
 }