コード例 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //Stop if you see another AI within range and start moving again when they are gone
        myRay = new Ray(transform.position, Vector3.right);
        Physics.Raycast(myRay.origin, myRay.direction, out myRCH, 1.5f, layerMask);
        if (myRCH.collider != null)
        {
            //Stop Next to Enemy and Ally
            if (myRCH.collider.tag == "Agent1" || myRCH.collider.tag == "Agent2")
            {
                agent1.velocity = new Vector3(0, 0, 0);
            }
            else
            {
                agent1.velocity = new Vector3(4, 0, 0);
            }

            //Attack
            if (myRCH.collider.tag == "Agent2")
            {
                attacktimer--;
                if (attacktimer <= 0)
                {
                    Agent2Controller AI2 = myRCH.collider.gameObject.GetComponent <Agent2Controller> ();
                    AI2.HP -= dmg;
                    anim.SetTrigger("Attack");
                    attacktimer = 45;
                }
            }
            else
            {
                attacktimer = 45;
            }
        }
        else
        {
            agent1.velocity = new Vector3(4, 0, 0);
        }

        if (hp < 5)
        {
            GetComponentInChildren <ParticleSystem> ().Play();
        }

        //Animation
        if (Mathf.Abs(agent1.velocity.x) > 0)
        {
            anim.SetBool("isWalking", true);
        }
        else
        {
            anim.SetBool("isWalking", false);
        }
        //Death
        if (hp <= 0)
        {
            AgentRespawn AR = GameObject.Find("Main Camera").GetComponent <AgentRespawn>();
            AR.DeleteAgent(gameObject);
        }
    }
コード例 #2
0
 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "CastleL")
     {
         GameObject   Cam      = GameObject.Find("Main Camera");
         AgentRespawn CastleHP = Cam.gameObject.GetComponent <AgentRespawn> ();
         CastleHP.CastleL -= 1;
         AgentRespawn AR = GameObject.Find("Main Camera").GetComponent <AgentRespawn>();
         AR.DeleteAgent(gameObject);
     }
 }
コード例 #3
0
 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "CastleL")
     {
         GameObject   Cam      = GameObject.Find("Main Camera");
         AgentRespawn CastleHP = Cam.gameObject.GetComponent <AgentRespawn> ();
         CastleHP.CastleL -= 1;
         CastleHP.Reduce('R');
         CameraShake CamShake = GameObject.Find("Main Camera").GetComponent <CameraShake> ();
         CamShake.MinorShake(.5f);
         AgentRespawn AR = GameObject.Find("Main Camera").GetComponent <AgentRespawn>();
         AR.DeleteAgent(gameObject);
     }
 }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        //Stop if you see another AI within range and start moving again when they are gone
        myRay = new Ray(transform.position, Vector3.right);
        Physics.Raycast(myRay.origin, myRay.direction, out myRCH, 2.5f, layerMask);
        if (myRCH.collider != null)
        {
            //Stop Next to Enemy and Ally
            if (myRCH.collider.tag == "Agent1" || myRCH.collider.tag == "Agent2")
            {
                agent1.velocity = new Vector3(0, 0, 0);
            }
            else
            {
                agent1.velocity = new Vector3(4, 0, 0);
            }

            //Attack
            if (myRCH.collider.tag == "Agent2")
            {
                attacktimer--;
                if (attacktimer <= 0)
                {
                    Agent2Controller AI2 = myRCH.collider.gameObject.GetComponent <Agent2Controller> ();
                    AI2.HP     -= dmg;
                    attacktimer = 45;
                }
            }
            else
            {
                attacktimer = 45;
            }
        }
        else
        {
            agent1.velocity = new Vector3(4, 0, 0);
        }

        if (hp <= 0)
        {
            AgentRespawn AR = GameObject.Find("Main Camera").GetComponent <AgentRespawn>();
            AR.DeleteAgent(gameObject);
        }
    }