コード例 #1
0
    private void Start()
    {
        // get the transform of the main camera
        if (Camera.main != null)
        {
            m_Cam = Camera.main.transform;
        }
        else
        {
            Debug.LogWarning(
                "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls.", gameObject);
            // we use self-relative controls in this case, which probably isn't what the user wants, but hey, we warned them!
        }

        // get the third person character ( this should never be null due to require component )
        m_Character = GetComponent <ThirdPersonCharacter>();

        attackAlterInstance = GetComponent <AttackAlter>();
    }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        int matchTagIndex = 0;

        foreach (string str in monsterHitboxTags)
        {
            if (other.gameObject.CompareTag(str))
            {
                break;
            }
            ++matchTagIndex;
        }

        if (canHit && attackInstance.startAttackFlag && matchTagIndex < monsterHitboxTags.Length)
        {
            canHit = false;
            StartCoroutine(coolDownTriggerDetection());

            Vector3 hitPos = other.ClosestPointOnBounds(transform.position);

            Debug.Log("Hit " + monsterHitboxTags[matchTagIndex]);


            if (SFXindex >= (HitSFX.Length))
            {
                SFXindex = 0;
            }
            else
            {
                HitSFX[SFXindex].Play();
                ++SFXindex;
            }

            GameObject hitParticle = Instantiate(hitParticlePrefab, hitPos, Quaternion.identity);
            hitParticle.transform.localScale = Vector3.one;

            // Special Effect?
            // hitParticle.transform.localScale = Vector3.one * 100f;

            MonsterHealthController.updateHealth(-1 * monsterDamage[matchTagIndex]);

            if (MonsterHealthController.healthInstance.hp <= 0)
            {
                isEnd = true;

                AttackAlter playerAtk = player.GetComponent <AttackAlter>();
                if (playerAtk)
                {
                    playerAtk.enabled = false;
                }

                ThirdPersonUserControl tpc = player.GetComponent <ThirdPersonUserControl>();
                if (tpc)
                {
                    tpc.enabled = false;
                }

                Animator anim = player.GetComponent <Animator>();
                if (anim)
                {
                    anim.SetInteger("Attack", 0);
                    anim.SetFloat("Move", 0);
                    anim.SetFloat("Turn", 0);
                    anim.SetBool("Run", false);
                }

                MonsterHealthController.gameObject.GetComponent <MonsterAI>().enabled = false;

                MonsterHealthController.gameObject.GetComponent <Animator>().SetTrigger("Die");

                StartCoroutine(GameOver());
            }

            if (isDebug)
            {
                GameObject g = Instantiate(DebugPrefab, hitPos, Quaternion.identity, other.gameObject.transform.parent);

                g.transform.localScale = new Vector3(1f / g.transform.parent.lossyScale.x, 1f / g.transform.parent.lossyScale.y, 1f / g.transform.parent.lossyScale.z);
                g.transform.localScale = Vector3.one * 100f;
                int hitNum = attackInstance.attackNum;

                switch (hitNum)
                {
                case 1:
                    g.GetComponent <Renderer>().material.color = Color.red;
                    break;

                case 2:
                    g.GetComponent <Renderer>().material.color = Color.green;
                    break;

                case 3:
                    g.GetComponent <Renderer>().material.color = Color.blue;
                    break;
                }
            }
        }
    }