Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problems upon problems

Discussion in 'Scripting' started by ChaosRobin, Aug 7, 2013.

  1. ChaosRobin

    ChaosRobin

    Joined:
    Mar 28, 2013
    Posts:
    58
    Hey, I have just started scripting with unity, I'm competing in the TornadoTwins Game competition, I just spent the entire day trying to the errors in this script. I cleared all of the errors it showed the first time around. then it gave me a list of new errors. I kept clearing the list of errors, and the list just kept growing every time I would fix something, and now, I'm stuck with 10 errors, and I cant figure out how to fix any of them. I hope you can explain to me what went wrong and what I can do to avoid problems like this in the future.

    I don't understand why but it seems like the compiler is having trouble with the functions.. I marked the 4 lines that the compiler marked

    Code (csharp):
    1. //FirstEver Java Script for Unity 3D. This Set of Varibles exists to bring my first
    2. //ever zombie character model to life.
    3.  
    4. var attackTurnTime = 0.7;
    5. var rotateSpeed = 120;
    6. var attackDistance = 17.0;
    7. var extraRunTime = 2.0;
    8. var damage = 1;
    9. var attackSpeed = 1.0;
    10. var attackRotateSpeed = 20.0;
    11. var idleTime = 1.6;
    12. var punchPosition = new Vector3 (0.4, 0, 0.7);
    13. var punchRadius = 1.1;
    14. var idleSound : AudioClip;
    15. var attackSound : AudioClip;
    16. private var attackingAngle = 10.0;
    17. private var isAttacking = false;
    18. private var lastPunchTime = 0.0;
    19. var target : Transform;
    20. private var characterController : CharacterController;
    21. characterController = GetComponent(CharacterController);
    22.  
    23. //Loops any animations. Tells zombie to use any item tagged as Player if dev has not
    24. //defined the target from the variable.
    25.  
    26. function Start ()
    27. {
    28. if (!target)
    29. target = GameObject.FindWithTag("Player").transform;
    30. animation.WrapMode = WrapMode.Loop;
    31. animation.Stop();
    32. }
    33. audio.Clip = idleSound;
    34. yield WaitForSeconds(Random.value);
    35. while (true)
    36. {
    37. yield idle();
    38. yield Attack();
    39. }
    40.  
    41. //Calls sounds, Plays idle when there is no player around. Rotates zombie toward player
    42. //once player has been tagged
    43.  
    44. function Idle()
    45. {
    46. animation.Play("idle");
    47. if(idleSound)
    48. {
    49. if(audio.clip != idleSound)
    50. {
    51. audio.Stop();
    52. audio.clip = idleSound;
    53. audio.loop = true;
    54. audio.Play(); // play the idle sound.
    55. }
    56. }
    57. yield WaitForSeconds (idleTime);
    58. while (true)
    59. {
    60. characterController.SimpleMove(Vector3.zero);
    61. yield WaitForSeconds(0.2);
    62. var offset = transform.position - target.position;
    63. if (offset.magnitude < attackDistance)
    64. return;
    65.   }
    66. (Errors here) function RotateTowardsPosition (targetPos : Vector3, rotateSpeed : float) : float
    67.  {
    68.  var relitave = transform.InverseTransformPoint(targetPos);
    69.  var angle = Mathf.Atan2 (relitave.x, relitave.z) * Mathf.Rad2Deg;
    70.  var maxRotation = rotateSpeed * Time.deltatime;
    71.  var clampedAngle = Mathf.Clamp(angle, -maxRotation, maxRotation);
    72.  transform.Rotate(0, clampedAngle, 0);
    73.  return angle;
    74.  }
    75.  
    76.  //Tells zombie to chase player, and play chase animation. animation.CrossFade("Chase")
    77.  //transitions from one idle or walk animation to another animation in this case chase.
    78.  
    79.  
    80. (Errors here) function Attack ()
    81.  {
    82.   isAttacting = true;
    83.   if (attackSound)
    84.   {
    85.   if (audio.clip != attackSound)
    86.   {
    87.   audio.Stop(); // stop the idling audio so we can switch out the  audio clip.
    88.   audio.clip = attackSound;
    89.   audio.loop = true; // change the clip, then play
    90.   audio.Play();
    91.   }
    92.   }
    93.   animation.CrossFade("Chase");
    94.   var angle : float;
    95.   angle = 180.0;
    96.   var time : float;
    97.   time = 0.0;
    98.   var direction : Vector3;
    99.   while (angle > 5 || time < attackTurnTime)
    100.   {
    101.   time += Time.deltaTime;
    102.   angle = Mathf.Abs(RotateTowardsPosition(target.position, rotateSpeed));
    103.   move = Mathf.Clamp01(90 - angle) /90;
    104.   animation["Chase"].weight = animation["Chase"].speed = move;
    105.   direction = transform.TransformDirect(Vector3.forward * attackSpeed * move);
    106.   characterController.SimpleMove(direction);
    107.   yield;
    108.   }
    109.   var timer = 0.0;
    110.   var lostSight = false;
    111.   while (timer < extraRunTime)
    112.   {
    113.   angle = RotateTowardsPosition(target.position, attackRotateSpeed);
    114.   if(Mathf.Abs(angle) > 40)
    115.   lostSight = true;
    116.   if (lostSight)
    117.   timer += time.deltaTime;
    118.   direction = transform.TransformDirection(Vector3.forward * attackSpeed);
    119.   characterController.SimpleMove(direction);
    120.  
    121.   //Tells zombie to cause damage to player if within range.
    122.  
    123.   var pos = transform.TransformPoint(punchPosition);
    124.   if(Time.time > lastPunchTime + 0.3  (pos - target.position).magnitude < punchRadius)
    125.   {
    126.   target.SendMessage("ApplyDamage", damage);
    127.   lastPunchTime =Time.time;
    128.   }
    129.   if (characterController.velocity.magnitude < attackSpeed * 0.3)
    130.   break;
    131.   yield;
    132.   }
    133.   isAttacking = false;
    134.   animation.CrossFade("idle");
    135.   }
    136.  
    137.   //Controlls attack animations
    138.  
    139. (Errors here) function OnDrawGizmosSelected ()
    140. {
    141. Gizmos.color = Color.yellow;
    142. Gizmos.DrawWireSphere (transform.TransformPoint(punchPosition), punchRadius);
    143. Gizmos.color = Color.red;
    144. Gizmos.DrawWireSphere (transform.position, attackDistance);
    145. }
    146. (Errors here)@script RequireComponent(AudioSource);
     
  2. login4donald

    login4donald

    Joined:
    Jan 3, 2012
    Posts:
    462
    What errors are the console displaying? What does it actually say if you please.
     
  3. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Code (csharp):
    1. yield idle();
    -=
    Code (csharp):
    1. function Idle()
    Your script is full of typos, missing brackets and other things.
    Follow some tutorials and some videos.