Search Unity

Identifier Missing chopping a tree

Discussion in 'Scripting' started by droni, Jul 25, 2014.

  1. droni

    droni

    Joined:
    Jul 25, 2014
    Posts:
    10
    Hello

    I have some problems with a script the error will be underlined the error message in the debug modus is Identifier Missing

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class trees : MonoBehaviour {
    6.  
    7.     public int chopDistence = 10;
    8.     public int chopTime = 5;
    9.     public bool inRange = false;
    10.     public Transform playere;
    11.  
    12.     void Update()
    13.     {
    14.          
    15.        float ; Vector3 player = playere.transform.position;
    16.         float ; Vector3 moveDirection = player - transform.position;
    17.      
    18.         if (moveDirection <= chopDistence)
    19.         {
    20.             inRange = true;
    21.         }
    22.         else if (moveDirection >= chopDistence)
    23.         {
    24.             inRange = false;
    25.         }
    26.      
    27.         if (inRange == true)
    28.         {
    29.             if(Input.GetMouseButtonUp(0))
    30.             {
    31.                 StartCoroutine (Timer (chopTime));
    32.             }
    33.         }
    34.  
    35.     }
    36.     IEnumerator Timer(float seconds)
    37.     {
    38.         yield return new WaitForSeconds(seconds);
    39.         Destroy(gameObject);
    40.         print ("Player_Inventory.players_wood");
    41.     }
    42. }
    43.  
     
    Last edited: Jul 25, 2014
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    few issues i can see here:

    first off: [code ] [/code ] tags when you paste in code to the forums please. Helps with formatting and makes it a lot more readable.

    secondly: playere is a transform, so asking for it's transform is a little redundant. Keep an eye on your data types.

    thirdly: if the variable "player" is the position from playere why isn't it called "playerPosition"? far more readable, would allow the public variable to be called "player" instead of the slightly odd "playere" (unless that's a language translation thing?). Keep your variables, functions and names in general as readable and specific as possible. When your code gets big, or when you open an old project to borrow some functionality you'll be thankful of things being what they say they are.

    lastly (and the actual issue the error is refering to): what is this
    Code (csharp):
    1.  
    2. float ; Vector3 player ...
    3. float ; Vector3 moveDirection ...
    4.  
    is it a float? or a Vector3? is this unityscript (except they're semicolons and not colons) or c#? it's all mixed up. I think you wanted
    Code (csharp):
    1.  
    2. Vector3 playerPosition = player.position;
    3.  
     
  3. droni

    droni

    Joined:
    Jul 25, 2014
    Posts:
    10
    if i dont put ther a float i cant write
    if (moveDirection <= chopDistence)
     
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class trees : MonoBehaviour {
    4.     public int chopDistence = 10;
    5.     public int chopTime = 5;
    6.     public bool inRange  = false;
    7.     public Transform playerT;
    8.     void Update()
    9.     {
    10.        
    11.         Vector3 player  = playerT.position;
    12.         Vector3 moveDirection = player - transform.position;
    13.    
    14.         if (moveDirection.magnitude <= chopDistence)
    15.         {
    16.             if(Input.GetMouseButtonUp(0))
    17.             {
    18.                 StartCoroutine (Timer (chopTime));
    19.             }
    20.         }
    21.     }
    22.     IEnumerator Timer(float seconds)
    23.     {
    24.         yield return new WaitForSeconds(seconds);
    25.         Destroy(gameObject);
    26.         print ("Player_Inventory.players_wood");
    27.     }
    28. }
    If your code is C# this version raises no errors.
     
  5. droni

    droni

    Joined:
    Jul 25, 2014
    Posts:
    10
    Thx you very much