Beispiel #1
0
 void FixedUpdate()
 {
     if (IsOnFire())
     {
         mortal.Damage(gameObject.tag, Time.deltaTime);
     }
 }
Beispiel #2
0
    void doDamage(GameObject otherObject)
    {
        Mortal m = otherObject.GetComponent <Mortal>();

        if (m != null)
        {
            if (m.Damage(gameObject.tag, amount))
            {
                onKill.Invoke();
            }
        }
    }
Beispiel #3
0
    void FixedUpdate()
    {
        switch (state)
        {
        case State.Dead:
            break;

        case State.Stop:
            if (!flammable.IsOnFire())
            {
                mortal.Damage(gameObject.tag, 5);
            }
            break;

        default:
            body.AddForce(GetMoveDirection().normalized *MAX_SPEED);
            break;
        }
        Vector2 playerDelta = playerData.position - body.position;

        if (playerDelta.sqrMagnitude < NEAR_PLAYER_DISTANCE * NEAR_PLAYER_DISTANCE)
        {
            // Near player
            if (state == State.Normal && canChase)
            {
                state = State.Chase;
            }
            if (hasPropane)
            {
                Instantiate(propanePrefab, transform.position, Quaternion.identity, transform.parent);
                hasPropane = false;
            }
        }
        else if (playerDelta.sqrMagnitude > FAR_PLAYER_DISTANCE * FAR_PLAYER_DISTANCE)
        {
            // Far player
            if (state == State.Chase)
            {
                state = State.Normal;
            }
        }

        Vector2 dist = destination - transform.position;

        if (dist.sqrMagnitude < 100)
        {
            Destroy(gameObject);
        }
    }
Beispiel #4
0
 void Start()
 {
     RaycastHit2D[] results = Physics2D.CircleCastAll(transform.position, EXPLOSION_RADIUS, Vector2.zero, 0);
     foreach (RaycastHit2D result in results)
     {
         Flammable flammable = result.collider.gameObject.GetComponent <Flammable>();
         if (flammable)
         {
             flammable.SetOnFire();
         }
         Mortal mortal = result.collider.gameObject.GetComponent <Mortal>();
         if (mortal)
         {
             mortal.Damage(gameObject.tag, EXPLOSION_DAMAGE);
         }
     }
     Camera.main.gameObject.GetComponent <CameraHelper>().Shake();
     SoundManager.Play(explosionSound);
 }
Beispiel #5
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (IsMoving() && body.velocity.sqrMagnitude > CRASH_SPEED_THRESHOLD)
     {
         SpriteSquish spriteSquish = collision.gameObject.GetComponent <SpriteSquish>();
         if (spriteSquish)
         {
             spriteSquish.SquishThin();
         }
         Flammable flammable = collision.gameObject.GetComponentInChildren <Flammable>();
         if (flammable)
         {
             this.flammable.SetOnFire();
             flammable.SetOnFire();
         }
         Mortal mortal = collision.gameObject.GetComponent <Mortal>();
         if (mortal)
         {
             mortal.Damage(gameObject.tag, CAR_CRASH_DAMAGE);
         }
     }
 }