Пример #1
0
    private void Update()
    {
        Ray        ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
        RaycastHit hitInfo;

        Debug.DrawRay(ray.origin, ray.direction * weaponRange, Color.green);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            if (Physics.Raycast(ray, out hitInfo, weaponRange))
            {
                if (hitInfo.collider.tag == "Tree") // Checks if the tree is hit and performs function for the tree
                {
                    treeHealth = hitInfo.collider.GetComponentInParent <TreeHealth>();
                    AttackTree();
                }

                else if (hitInfo.collider.tag == "Zombie")                         // Checks if the tagged Zombie is hit
                {
                    zombieAI = hitInfo.collider.GetComponent <AdvancedZombieAI>(); // Finds the script component called "BasicAI"
                    AttackEnemy();
                }
            }
        }
    }
Пример #2
0
    private void Update()
    {
        Ray        ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
        RaycastHit hitInfo;

        if (Input.GetKeyDown(KeyCode.Mouse0))                   // Shoot at target when we mouse click
        {
            if (Physics.Raycast(ray, out hitInfo, weaponRange)) // Checks for collision of the ray
            {
                if (hitInfo.collider.tag == "Zombie")
                {
                    zombieAI = hitInfo.collider.GetComponent <AdvancedZombieAI>();
                    zombieAI.TakeDamage(Damage());
                }
            }
        }
    }
Пример #3
0
 private void Start()
 {
     advancedZombieAI = GetComponentInParent <AdvancedZombieAI>(); // Finds the AdvancedZombieAI script
 }