Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Enemy ai script error

Discussion in 'Getting Started' started by phantomunboxing, Mar 24, 2016.

  1. phantomunboxing

    phantomunboxing

    Joined:
    Nov 10, 2015
    Posts:
    43
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Ai : MonoBehaviour
    5. {
    6.  
    7.  
    8. public Transform enemy;
    9. public Transform playertrans;
    10. public GameObject enemyobject;
    11. public float speed;
    12. public bool enemycansee;
    13. public float distance;
    14. public GameObject player;
    15. public float range;
    16.  
    17.     void Update ()
    18.     {
    19.         if (enemycansee)
    20.         {
    21.             float step = speed * Time.deltaTime;
    22.             transform.rotation = Quaternion.RotateTowards(transform.rotation, playertrans.rotation, step);
    23.             enemy.transform.Translate(Vector3.forward * Time.deltaTime * speed);
    24.         }
    25.         else
    26.         {
    27.             enemycansee = false;
    28.         }
    29.             if (Vector3.Distance(player.position, enemyobject.position) < range)
    30.         {
    31.             enemycansee = true;
    32.         }
    33.     }
    34. }
    35.  
    Error line 34 UnitEngine.GameObject does not contain a definition for position and no extension method position accepting a first argument type UnityEngine.GameObject

    ERROR SOLVED :D
     
    Last edited: Mar 24, 2016
  2. phantomunboxing

    phantomunboxing

    Joined:
    Nov 10, 2015
    Posts:
    43
    ERROR FOUND