Example #1
0
    public void Init(float force, float initLife, float initVelocity, OnLifeEnd onLifeEnd, float angle = 0)
    {
        angle = Mathf.Deg2Rad * (90 + angle);
        gameObject.transform.localRotation = Quaternion.Euler(Vector3.up * angle);
        Vector3 direction = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0);

        this.force     = direction.normalized * force;
        this.life      = initLife;
        this.velocity  = direction.normalized * initVelocity;
        this.onLifeEnd = onLifeEnd;
    }
Example #2
0
 public void Update()
 {
     velocity += force * Time.deltaTime;
     gameObject.transform.position += velocity * Time.deltaTime;
     life -= Time.deltaTime;
     if (life <= 0)
     {
         if (onLifeEnd != null)
         {
             onLifeEnd(gameObject);
             onLifeEnd = null;
         }
     }
 }