Search Unity

'destination' is not a member of 'UnityEngine.Component'

Discussion in 'PSM' started by MonkeyKasai, Aug 31, 2014.

  1. MonkeyKasai

    MonkeyKasai

    Joined:
    Jan 4, 2014
    Posts:
    40
    Hey guys,
    So when I Build & Run my game I get a Error building Player because scripts had compiler errors. My game works perfectly fine when I test it, but after I tried building it I can no long test the game unless I open the project up on my normal Unity build instead of Unity PSM. The errors happens on both my desktop and laptop.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Post code (and use code tags).

    --Eric
     
  3. MonkeyKasai

    MonkeyKasai

    Joined:
    Jan 4, 2014
    Posts:
    40
    ops sorry heres the code
    This is my movement for my enemy

    Code (JavaScript):
    1. var target : Transform;
    2. var targety : Vector3;
    3. var gravity = 20.0;
    4.  
    5. var minTarX : float = 25;
    6. var maxTarX : float = 35;
    7. var minTarZ : float = -5;
    8. var maxTarZ : float = 5;
    9. var tarX : float;
    10. var tarZ : float;
    11. var tarY : float;
    12.  
    13. var timeSwitch : int;
    14.  
    15. function Start (){
    16.  
    17.     if(target == null){
    18.     target = GameObject.FindWithTag("Player").transform;
    19.     }
    20.  
    21.     targety = this.transform.position;
    22.  
    23.     CreateTarPoint();
    24.  
    25. }
    26.  
    27. function Update(){
    28.  
    29.     targety = this.transform.position;
    30.  
    31.     tarY = targety.y;
    32.  
    33.     if(animation.IsPlaying("Dead") && animation.IsPlaying("Hurt")){
    34.      
    35.         tarX = targety.x;
    36.         tarZ = targety.z;
    37.      
    38.     }
    39.  
    40.     if (!animation.IsPlaying("Dead") && !animation.IsPlaying("Hurt")){
    41.      
    42.         if(target == null){
    43.         transform.GetComponent("NavMeshAgent").destination = target.position;
    44.         }else{
    45.             if(timeSwitch <= 0){
    46.                 timeSwitch = 700;
    47.                 CreateTarPoint();
    48.             }else{
    49.                 transform.GetComponent("NavMeshAgent").destination = new Vector3(tarX, tarY, tarZ);
    50.                 timeSwitch -= 1 - Time.deltaTime;
    51.             }
    52.         }
    53.     }
    54. }
    55.  
    56. function CreateTarPoint(){
    57.  
    58.     tarX = Random.Range(minTarX, maxTarX);
    59.     tarZ = Random.Range(minTarZ, maxTarZ);
    60.     timeSwitch = Random.Range(400, 1000);
    61.  
    62. }
     
    Last edited: Aug 31, 2014
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    GetComponent shouldn't use quotes...if you use GetComponent(Type) then it returns Type, but if you use GetComponent("Type") then it just returns Component, which as the error says has no member called "destination".

    --Eric
     
    MonkeyKasai likes this.
  5. MonkeyKasai

    MonkeyKasai

    Joined:
    Jan 4, 2014
    Posts:
    40
    Thank you soooo much!
    works now :)