예제 #1
0
    void Awake()
    {
        int i=0;

        //Mesh Setup

        int meshCount=0;

        for(i=0; i<2; i++){
            foreach (Renderer m in gameObject.GetComponentsInChildren<Renderer>()){
                if(i==1){
                    mesh[meshCount]=m;
                }
                meshCount++;
            }

            if(i==0){
                mesh=new Renderer[meshCount];
            }

            meshCount=0;
        }

        //Player or Enemy

        if(GetComponent<SCR_characterControl>()){
            gameObject.tag="Player";
            isPlayer=true;
            cc=GetComponent<SCR_characterControl>();
            SetRotAngle(transform.position+(Vector3.forward*-10f));
            SetRotTarget();
        }	else {
            gameObject.tag="Enemy";
            isPlayer=false;
            invulnerable=true;
            ai=GetComponent<SCR_enemyAI>();
            StartFlash(1,4);
            float patrolMult=0.5f;
            runSpeedArray=new float[2]{	runSpeed,
                                        runSpeed*patrolMult
            };
            runAnimSpeedPatrol=(animSpeed[1]*patrolMult);
        }

        //Melee or Ranged

        if(GetComponent<SCR_characterMelee>()){
            characterMelee=GetComponent<SCR_characterMelee>();
            characterMelee.StartUp(isPlayer);
            melee=true;
        }	else {
            characterRanged=GetComponent<SCR_characterRanged>();
            melee=false;
        }

        //Animation Setup

        int animCount=0;

        for(i=0; i<2; i++){
            foreach (AnimationState clip in GetComponent<Animation>()) {
                if(i==1){
                    animArray[animCount]=clip.name;
                }
                animCount++;
            }

            if(i==0){
                animArray=new string[animCount];
                animCount=0;
            }
        }

        //Set the cross fade speed for each animation
        animBlendSpeed=new float[9]{		0.15f,
                                            0.15f,
                                            0.1f,
                                            0.15f,
                                            0.0f,
                                            0.0f,
                                            0.0f,
                                            0.0f,
                                            0.0f
        };

        //Set the speed for each animation
        for(i=0; i<animArray.Length; i++){
            if(GetComponent<Animation>()[animArray[i]]){
                GetComponent<Animation>()[animArray[i]].speed=animSpeed[i];
            }
        }

        if(rollSound){
            SND_roll=SCR_main.CreateSound(transform,rollSound,false,true);
        }

        if(GetComponent<BoxCollider>()){
            hitBoxSize=(GetComponent<BoxCollider>().size.x*transform.localScale.x*0.5f);
        }
        transform.rotation=rotTarget;

        if(isPlayer){
            cc.StartUp();
        }	else {
            ai.StartUp();
        }
    }
예제 #2
0
    void Awake()
    {
        int i = 0;

        //Mesh Setup

        int meshCount = 0;

        for (i = 0; i < 2; i++)
        {
            foreach (Renderer m in gameObject.GetComponentsInChildren <Renderer>())
            {
                if (i == 1)
                {
                    mesh[meshCount] = m;
                }
                meshCount++;
            }

            if (i == 0)
            {
                mesh = new Renderer[meshCount];
            }

            meshCount = 0;
        }

        //Player or Enemy

        if (GetComponent <SCR_characterControl>())
        {
            gameObject.tag = "Player";
            isPlayer       = true;
            cc             = GetComponent <SCR_characterControl>();
            SetRotAngle(transform.position + (Vector3.forward * -10f));
            SetRotTarget();
        }
        else
        {
            gameObject.tag = "Enemy";
            isPlayer       = false;
            invulnerable   = true;
            ai             = GetComponent <SCR_enemyAI>();
            StartFlash(1, 4);
            float patrolMult = 0.5f;
            runSpeedArray = new float[2] {
                runSpeed,
                runSpeed *patrolMult
            };
            runAnimSpeedPatrol = (animSpeed[1] * patrolMult);
        }



        //Melee or Ranged

        if (GetComponent <SCR_characterMelee>())
        {
            characterMelee = GetComponent <SCR_characterMelee>();
            characterMelee.StartUp(isPlayer);
            melee = true;
        }
        else
        {
            characterRanged = GetComponent <SCR_characterRanged>();
            melee           = false;
        }

        //Animation Setup

        int animCount = 0;

        for (i = 0; i < 2; i++)
        {
            foreach (AnimationState clip in GetComponent <Animation>())
            {
                if (i == 1)
                {
                    animArray[animCount] = clip.name;
                }
                animCount++;
            }

            if (i == 0)
            {
                animArray = new string[animCount];
                animCount = 0;
            }
        }

        //Set the cross fade speed for each animation
        animBlendSpeed = new float[9] {
            0.15f,
            0.15f,
            0.1f,
            0.15f,
            0.0f,
            0.0f,
            0.0f,
            0.0f,
            0.0f
        };

        //Set the speed for each animation
        for (i = 0; i < animArray.Length; i++)
        {
            if (GetComponent <Animation>()[animArray[i]])
            {
                GetComponent <Animation>()[animArray[i]].speed = animSpeed[i];
            }
        }

        if (rollSound)
        {
            SND_roll = SCR_main.CreateSound(transform, rollSound, false, true);
        }


        if (GetComponent <BoxCollider>())
        {
            hitBoxSize = (GetComponent <BoxCollider>().size.x *transform.localScale.x *0.5f);
        }
        transform.rotation = rotTarget;

        if (isPlayer)
        {
            cc.StartUp();
        }
        else
        {
            ai.StartUp();
        }
    }