예제 #1
0
    private void Awake()
    {
        Speed    = 5f;
        _borders = new Vector3(-6f, 0f, 0f);

        _lifeText = GameObject.FindGameObjectWithTag("LifeText").GetComponent <LifeText>();
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        //When the enemies invade the player territory
        if (other.gameObject.CompareTag("Enemy"))
        {
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                Player.lives--;                                                                                                                                                              //Decrease the players lives
                LifeText lives = GameObject.FindGameObjectWithTag("Lives").GetComponent <LifeText>();
                lives.UpdateLivesText();                                                                                                                                                     //Show the current lives
                GameObject instanceParticles = Instantiate(particles, new Vector3(other.transform.position.x, other.transform.position.y, other.transform.position.z), Quaternion.identity); //Particles
                if (Player.lives > 0)                                                                                                                                                        //If the player isn't dead play the zombie blip sound
                {
                    Audio.PlaySound("enemyEnter");
                }
                Destroy(other.gameObject);

                if (Player.lives <= 0)
                {
                    Player player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
                    player.OnPlayerDeath();
                }
            }
        }
    }
예제 #3
0
    public void ChangePoint(string name, int value)
    {
        if (!TextCanvas.activeSelf)
        {
            GetComponent <Animator>().Play("CanvasAnimation");
        }

        switch (name)
        {
        case "Shield":
            ShieldPoints += value;
            ShieldText.GetComponent <Text>().text = ShieldPoints.ToString();
            break;

        case "Spike":
            SpikePoints += value;
            SpikeText.GetComponent <Text>().text = SpikePoints.ToString();
            break;

        case "Life":
            LifePoints += value;
            LifeText.GetComponent <Text>().text = LifePoints.ToString();
            break;
        }
        BaseCreator.GetComponent <CreateBase>().CheckButton();
    }
예제 #4
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         Audio.PlaySound("playerCollect");
         Player.lives++;
         LifeText lives = GameObject.FindGameObjectWithTag("Lives").GetComponent <LifeText>();
         lives.UpdateLivesText(); //Show the current lives
         Destroy(gameObject);
     }
 }
예제 #5
0
        protected override void Initialize()
        {
            keyboardController = new KeyboardController();
            gamepadController  = new GamepadController();
            level     = new Level(this);
            lifeText  = new LifeText(this);
            resetTime = false;
            InitializeCommands();

            base.Initialize();
        }
예제 #6
0
    private void Start()
    {
        if (!ballPrefab)
        {
            Debug.LogError("Could not find ball prefab on player");
        }

        lifeText = FindObjectOfType <LifeText>();

        lifeText.UpdateHealthText(health);
        SetUpWorldBoundaries();
    }
예제 #7
0
    /// <summary>
    /// 被攻击————————以后需要改成根据敌人的攻击类型和级别进行伤害判定
    /// </summary>
    /// <param name="atk"></param>
    /// <returns></returns>
    public bool hurt(int atk)
    {
        //如果已死,返回
        if (_currentState == DeadState)
        {
            return(true);
        }

        //减血
        _data.HP -= atk;

        //血条
        _lifeLine.OnHit(atk);

#if false
        //飘伤害
        GameObject lifeTextObj = ResourceManager.getInstance().getGameObject("DmgText");
        LifeText   lifeText    = lifeTextObj.GetComponent <LifeText>();
        if (lifeText != null)
        {
            lifeText.setText(this, atk.ToString());
        }
#endif

#if true
        // 飘血特效
        GameObject effect = ResourceManager.getInstance().getGameObject("Hit_TongYong_001_big");
        effect.transform.position = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + 0.5f, this.gameObject.transform.position.z);
        effect.transform.SetParent(this.gameObject.transform);
#endif

        //是否死亡
        if (_data.HP <= 0)
        {
            walkStop();

            GameObject.Destroy(_lifeTestObj);

            //进入死亡状态
            setState(DeadState);
        }
#if false
        else
        {
            //进入受击状态
            setState(_hurtState);
        }
#endif

        //返回
        return(_data.HP <= 0);
    }
예제 #8
0
        protected override void Initialize()
        {
            level = new Level(this);
            keyboardController            = new KeyboardController(this);
            gamepadController             = new GamepadController();
            menuKeyboardController        = new MenuKeyboardController(this);
            collectibleKeyboardController = new CollectiblesKeyboardController(this);
            playerName = "3Pros1LenUFO";
            lifeText   = new LifeText(this);
            resetTime  = false;
            InitializeCommands();

            base.Initialize();
        }
예제 #9
0
    //overrideしたStart
    protected override void Start()
    {
        animator     = GetComponent <Animator>();
        battleSystem = GetComponent <BattleSystem>();
        status       = GetComponent <Status>();
        lifetext     = GetComponentInChildren <LifeText>();

        //満腹度を初期化
        food             = GameManager.instance.playerFoodPoints;
        status.CurrentHp = GameManager.instance.playerHP;

        isGameend = false;

        //継承元のStartを呼ぶ
        base.Start();
    }
예제 #10
0
    //overrideしたStart
    protected override void Start()
    {
        //自身をGameManagerに登録
        GameManager.instance.AddEnemyToList(this);

        animator     = GetComponent <Animator>();
        battleSystem = GetComponent <BattleSystem>();

        //targetをPlayerのtransformに設定
        target = GameObject.FindGameObjectWithTag("Player").transform;

        skipMove = false;

        //GameObject lifeTextObj = Instantiate(lifetextPrefab);
        //lifeTextObj.transform.parent = GameObject.Find("LifeTextManager").transform;
        //myLifeText = lifeTextObj.GetComponent<LifeText>();
        //myLifeText.LifeOwner = gameObject;

        playerlife = target.GetComponentInChildren <LifeText>();

        base.Start();
    }
예제 #11
0
    private void HitEnemy(GameObject enemy)
    {
        //相手がenemyだったら
        Status receiver = enemy.GetComponent <Status>();

        int damage = 0;

        //自身とEnemyをバトルさせる
        damage = battleSystem.Battle(receiver);

        //攻撃した際のアニメーションを再生
        animator.SetTrigger("playerChop");

        //enemyのlifeTextを取得
        LifeText lifeText = enemy.GetComponentInChildren <LifeText>();//.LifeText;

        lifeText.CallDamageText(damage);

        if (receiver.IsDead)
        {
            Destroy(enemy);
        }
    }
    private void Start()
    {
        LifeText lives = GameObject.FindGameObjectWithTag("Lives").GetComponent <LifeText>();

        lives.UpdateLivesText();
    }