Example #1
0
    private void OnTriggerEnter(Collider _c)
    {
        if (_c.gameObject.GetComponent <PlanetAI>())
        {
            Debug.Log("Hit until Planet");
            PlanetAI planet = _c.gameObject.GetComponent <PlanetAI>();
            PlayerController.Instance.SubtractHealth(planet.Damage);
                        #if UNITY_ANDROID || UNITY_IPHONE
            Handheld.Vibrate();
                        #endif
            planet.IsEnabled = false;
            StartCoroutine(EffectManager.Instance.PlayExplosion(2.0f, _c.gameObject));
        }
        if (_c.gameObject.GetComponent <NoteAI>())
        {
            Debug.Log("Hit until Notes");
            NoteAI note = _c.gameObject.GetComponent <NoteAI>();
            if (NoteSequence.Instance.GetCurrentNote() == note.Type)
            {
                NoteSequence.Instance.NextNote();
                switch (NoteSequence.Instance.GetCurrentNote())
                {
                case NoteType.typeA:    EffectManager.Instance.ChangeAuroraWaveColor(Color.cyan);       break;

                case NoteType.typeB:    EffectManager.Instance.ChangeAuroraWaveColor(Color.yellow);     break;

                case NoteType.typeC:    EffectManager.Instance.ChangeAuroraWaveColor(Color.green);      break;

                case NoteType.typeD:    EffectManager.Instance.ChangeAuroraWaveColor(Color.red);        break;
                }
                note.IsEnabled = false;
                StartCoroutine(EffectManager.Instance.PlayFireworks(1.0f));
                PointsManager.Instance.CurrentScore += PointsManager.Instance.NotePoints;
            }
        }
    }
    void Update()
    {
        if (player == null)
        {
            player = GameObject.Find("Player");
        }
        switch (state)
        {
        case 0:
            TargetPos = PathPoints[0].position;
            MoveToPosition();
            if (Time.time >= NextTimeReturn)
            {
                state = GenerateRandomNumState(0, 2);
                Debug.Log("called");
                if (state == 0)
                {
                    NextTimeReturn = Time.time + WaitReturnPeriod;
                }
            }
            break;

        case 1:
            int random = GenerateRandomNumState(1, PathPoints.Count);
            TargetPos = PathPoints[random].position;
            state     = 4;
            break;

        case 2:
            for (int i = 0; i < noteman.mList.Count; i++)
            {
                if (noteman.mList[i].IsEnabled == true)
                {
                    activeAI.Add(noteman.mList[i]);
                }
            }
            for (int z = 0; z < activeAI.Count; z++)
            {
                float distance = Vector3.Distance(activeAI[z].gameObject.transform.position, player.transform.position);
                Debug.Log(distance);
                if (distance < 500 && distance > 200)
                {
                    ChaseObject = activeAI[z];
                }
            }
            activeAI.Clear();
            if (ChaseObject != null)
            {
                state = 5;
            }
            else
            {
                state = 2;
            }
            break;

        case 4:
            if (this.transform.position != TargetPos)
            {
                MoveToPosition();
            }
            else
            {
                state = GenerateRandomNumState(0, 3);
                if (state == 0)
                {
                    NextTimeReturn = Time.time + WaitReturnPeriod;
                }
            }
            break;

        case 5:
            this.transform.position = Vector3.MoveTowards(this.transform.position, ChaseObject.gameObject.transform.position, Time.deltaTime * NotesManager.Instance.NoteSpeed + 1.5f);
            if (this.transform.position == ChaseObject.gameObject.transform.position)
            {
                state = 1;
                ChaseObject.IsEnabled = false;
            }
            break;

        case 3:
            this.transform.position = Vector3.MoveTowards(this.transform.position, this.transform.position + (50 * EvasionDirection), Time.deltaTime * 100);
            break;
        }
    }