示例#1
0
    //Event called when damaged by an attack
    public void Damage(int Damage = 0)
    {
        //Reduce health
        Health -= Damage;

        ////Play damage animation
        PingPongSpriteColor.PlayColorAnimation();

        //Check if dead
        if (Health <= 0)
        {
            //Send enemy destroyed notification
            GameManager.Notifications.PostNotification(this, "EnemyDestroyed");

            //Play collection sound, if audio source is available
            if (SFX)
            {
                SFX.PlayOneShot(DestroyAudio, 1.0f);
            }

            //Remove object from scene
            DestroyImmediate(gameObject);

            //Clean up old listeners
            GameManager.Notifications.RemoveRedundancies();
        }
    }
示例#2
0
    //------------------------------------------------
    //Called on object start
    protected virtual void Start()
    {
        GameManager.Notifications.AddListener(this, "SaveGamePrepare");
        GameManager.Notifications.AddListener(this, "LoadGameComplete");

        InitAudio();

        PingPongSpriteColor = GetComponent <PingPongSpriteColor>();

        //Get NavAgent Component
        Agent = GetComponent <NavMeshAgent>();

        //Get Player Controller Component
        PlayerController = GameObject.Find("Player").GetComponentInChildren <PlayerController>();

        //Get Player Transform
        PlayerTransform = PlayerController.transform;

        //Get Enemy Transform
        ThisTransform = transform;

        //Set default state
        ChangeState(ActiveState);
    }