Beispiel #1
0
    void RightClick()
    {
        if (!character)
        {
            //Debug.Log("No character selected.");
            return;
        }

        Ray ray;

        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit       hit;
        CharacterDetails controller = character.GetComponent <CharacterDetails>();

        if (Physics.Raycast(ray, out hit))
        {
            //Attacking
            if (hit.transform.tag == "Character")
            {
                Debug.Log(character.name + " is attacking " + hit.transform.name);
                controller.Attack(hit);
            }
            //Moving
            else if (Physics.Raycast(ray, out hit, 100f, terrainMask))
            {
                Debug.Log("Move to " + hit.point.x + "," + hit.point.y + "," + hit.point.z);
                controller.Move(hit);
            }
        }
    }
Beispiel #2
0
    private int ZombiePlay(GameObject[] enemies)
    {
        int n   = enemies.Length;
        int ret = 1;

        //try to attack anything nearby
        for (int i = 0; i < n; ++i)
        {
            if (enemies[i] && ret > 0)
            {
                ret = self.Attack(enemies[i]);
                if (ret == -1)
                {
                    mode = "Dead";
                    Debug.Log("Mode error a dead character wasn't maked as dead.");
                    return(-1);
                }
                if (ret == -2)
                {
                    Debug.Log("Character doesn't have enough energy to attack.");
                    return(0);
                }
            }
            ret = 1;
        }
        //move to a "random" enemy
        int rnd = Random.Range(0, n - 1);

        ret = -1;
        for (int i = rnd; i < n; ++i)
        {
            if (enemies[i] && ret < 0)
            {
                self.Move(enemies[i].GetComponent <Rigidbody>());
                ret = i;
            }
        }
        if (ret < 0)
        {
            for (int i = 0; i < rnd; ++i)
            {
                if (enemies[i] && ret < 0)
                {
                    self.Move(enemies[i].GetComponent <Rigidbody>());
                    ret = i;
                }
            }
        }
        if (ret < 0)
        {
            Debug.Log("No valid enemies to move towards");
            return(-1);
        }
        ret = 1;
        //try to attack anything nearby
        for (int i = 0; i < n; ++i)
        {
            if (enemies[i] && ret > 0)
            {
                ret = self.Attack(enemies[i]);
                if (ret == -2)
                {
                    Debug.Log("Character doesn't have enough energy to attack.");
                    return(0);
                }
            }
            ret = 1;
        }
        return(0);
    }