Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-4
Question by pookiw · Apr 04, 2013 at 04:18 PM · errorassignment

Scripting Errors I cannot fix, Could use a helping hand and someone to tell me how to fix it:PART II

Well for an assignment I was to fix a few scripts on my own. I managed to fix one fully by myself and another to only having a few errors which kind people on here helped me fix. Now Ive managed to get this final script down to the last few errors. (Going from 22 to 5 and being stuck) IF anyone is willing to assist me in fixing the errors and telling me what was wrong with them and how to fix it I would really be grateful. I'm very new to the scripting scene but I want to learn all I can!

 public var health : int = 5;        // number of hits before game over
 public var moveSpeed : int = 3;    // horizontal speed
 public var jumpSpeed : float = 8;    // jumping speed
 public var turnSpeed : float = 2;    // turning rate
 
 private var controller : CharacterController;    // reference to CharacterController component
 private var velocity : Vector;                    // current speed
 
 function Start ()
 {
 
 }
 
 function Update ()
 {
     // assume no input
     velocity.x = 0;
     velocity.z = 0;
     
     // forward
     if (Input.GetKey("w") || Input.GetKey("up"))
     {
         velocity + transform.forward * moveSpeed;
     }
     // back
     else if(Input.GetKey("s") || Input.GetKey("down"))
     {
         velocity + transform.back * moveSpeed;
     }
     // turn left
     if(Input.GetKey("a") || Input.GetKey("left"))
     {
         transform.rotate(0, -turnSpeed, 0);
     }
     // turn right
     else if(Input.GetKey("d") || ("right"))
     {
         Transform.Rotate(0, turnspeed, 0);
     }
     
     if(isGrounded)
     {
         // jump
         if(Input.GetKeyDown("space"))
         {
             velocity += transform.up * jumpSpeed;
         }
         else
         {
             velocity.y = 0;
         }
     }
     // gravity
     velocity += Physics.gravity * Time.deltaTime;
     // apply motion
     controller.Move(velocity * Time.deltaTime);
 
 function onTriggerEnter()
 {
     // detection radius
     if(trigger.name == "Enemy")
     {
         // set enemy to alert
         // Enemy is the name of the enemy script
         // alert is a variable on the Enemy script
         trigger.GetComponent(Enemy).alert = true;
     }
     // getting hit
     else if(trigger.name == "Body")
     {
         health--;
         if(health <= 0)
         {
             transform.DetachChildren();
             Destroy(gameObject);
         }
     }
 }
 
 function OnTriggerEnter(trigger : collider)
 {
     // leaving detection radius
     if(trigger.name == "Enemy")
     {
         trigger.GetComponent(Enemy).alert = false;
     }
 } 
Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Apr 04, 2013 at 04:18 PM 3
Share

Format your code : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

Then actually tell us the errors. Once the script is readable, and the errors are clearly stated, then you will probably get some help.

avatar image AlucardJay · Apr 04, 2013 at 05:08 PM 2
Share

Thanks to Statement for formatting your code. Don't forget to thank him, and then still watch the video I linked.

line 23, missing an equals sign :

 velocity += transform.forward * moveSpeed;

line 28, missing an equals sign :

 velocity += transform.back * moveSpeed;

line 33, capitol R in Rotate

 transform.Rotate(0, -turnSpeed, 0);

that's all I can see without your error messages. Fix these, and then check for any other compilation errors. Be sure to tell us the errors, and remember to format your code =]

Oh, and line 3, Vector3 :

 private var velocity : Vector3;

And there is something wrong with you having 2 function onTriggerEnter()

the first one is spelled wrong (lowercase o ins$$anonymous$$d of uppercase O), and has no parameters :

 function onTriggerEnter()

The second one is what you want, move all the trigger code to there :

 function OnTriggerEnter(trigger : collider)

This is a real cut and paste job here. You really need to experiment with some simple projects, and learn the basics of coding :

  • http://www.youtube.com/watch?v=ja7z5pYFJXQ

  • http://www.youtube.com/watch?v=n1mgXiYiVWo

  • http://www.youtube.com/watch?v=pktdjxOpgDA

avatar image Graham-Dunnett ♦♦ · Apr 04, 2013 at 07:55 PM 1
Share

Line 56 needs a closing brace.

avatar image landon912 · Apr 04, 2013 at 08:29 PM 0
Share

Line 38 should have a lower case "t" in transform.

avatar image landon912 · Apr 04, 2013 at 08:31 PM 0
Share

Also, the second OnTriggerEnter shouldn't be deleted but changed to OnTriggerExit.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nachtmahr · Apr 04, 2013 at 08:23 PM

CharacterController was never assigned http://docs.unity3d.com/Documentation/ScriptReference/Component.GetComponent.html you do Calculation but no assignment yourvar = yourDesiredValue; Syntax Errors, wrong function names and Parameters take a look at http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.html

like alucardj suggestet learn the basics and how to find and resolve Bugs. Use the Manual there full of Examples of Code usage.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Animation spins wildly after completed 0 Answers

NullReferenceException problem 2 Answers

Scripting Error! - UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer

Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges