Ejemplo n.º 1
0
    void Update()
    {
        if (hasAi && StageHandler.InStageBounds(transform.position))
        {
            if (!ai.inBounds)
            {
                ai.nextFire = Time.time;
                ai.inBounds = true;
            }
        }
        else
        {
            ai.inBounds = false;
        }

        if (hitOnFrame)
        {
            SFXHandler.PlaySound("enemyhit_loop", true);
            hitOnFrame = false;
        }
        else
        {
            SFXHandler.StopSound("enemyhit_loop");
        }
    }
Ejemplo n.º 2
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     // Only take damage when on-screen
     if (collider.CompareTag("Friendly") && StageHandler.InStageBounds(transform.position))
     {
         hitOnFrame = true;
         TakeDamage(PlayerController.instance.damage);
     }
 }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        if (hasAi && StageHandler.InStageBounds(transform.position))
        {
            if (ai.inBounds)
            {
                while (Time.time > ai.nextFire)
                {
                    ai.Shoot();

                    ai.nextFire += ai.firedelay;
                }
            }
        }
    }
    void FixedUpdate()
    {
        // Follows enemies, i.e. it only works for friendly bullets
        if (follow)
        {
            GameObject target = StageHandler.GetClosestEnemy(transform.position);
            if (target != null)
            {
                // The magnitude of the cross product provides rotation amount
                float rot = Vector3.Cross(transform.up, Vector3.Normalize(target.transform.position - transform.position)).z;

                transform.Rotate(Vector3.forward, rot * rotSpeed * Time.fixedDeltaTime);
            }
        }

        // Use Vector3 instead of transform.right because of the relativeTo parameter
        transform.Translate(Vector3.up * speed * Time.fixedDeltaTime);

        // Kill if out of bounds, more reliable than edge colliders
        if (!StageHandler.InStageBounds(transform.position))
        {
            Object.Destroy(gameObject);
        }
    }