Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by youngtraffords96 · Jul 02, 2011 at 06:48 PM · errorbce0044

Errors in Scripting

I am sorry that I keep having to post new questions. I am new, but I think I have finaly figured out how to use the 10101 button correctly now. Haha. So I have multiple errors in my script. I try to resolve them by following the directions on the alerts, but it just creates new ones. I am down to several last errors.

BCE0044: expecting (, found 'OnControllerHit'

BCE0044: expecting ), found ':'

UCE0001: ';' expected. Insert a semicolon at the end

BCE0043: Unexpected token: )

BCE0043: Unexpected token: if

UCE0001: ';' expected. Insert a semicolon at the end

BCE0044: expecting :, found '='

Here is my script....

//Moving Around

 var speed = 3.0;
 var rotateSpeed = 3.0;
 
 //Shooting
 var bullitPrefab:Transform;
 
 //Dying
 private var dead = false;
 
 //Getting Hit
 var tumbleSpeed = 800;
 var decreaseTime = 0.01;
 var decayTime = 0.01;
 static var gotHit = false;
 private var backup = [tumbleSpeed, decreaseTime, decayTime];
 
 function LateUpdate()
 {
         if(dead)
 
     
     if(gotHit)
     {
             if(tumbleSpeed < 1)
             {
                     //we're not hit anymore... reset and get back in the game!
                     tumbleSpeed = backup[0];
                     decreaseTime = backup[1];
                     decayTime = backup[2];
                     gotHit = false;
             }
             else
             {
                     //we're hit! Spin our character around
                     transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
                     tumbleSpeed = tumbleSpeed-decreaseTime;
                     decreaseTime += decayTime;
             }
     }
 function OnControllerHit (hit : ControllerColliderHit) //onTriggerEnter : collider 
 {
         if(hit.gameObject.tag == "fallout")
         {
                 dead = true; //the error is on this line, please help!
                 //subtract life here
                 HealthControl.LIVES -= 1;
         }
         
         if(hit.gameObject.tag == "enemyProjectile")
         {
                 gotHit = true;
         }
 }
 
 function Update () 
 { 
         var controller : CharacterController = GetComponent(CharacterController);
 
         // Rotate around y - axis
         transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
         var forward = transform.TransformDirection(Vector3.forward);
         var curSpeed = speed * Input.GetAxis ("Vertical");
         controller.SimpleMove(forward * curSpeed);
         
         if(Input.GetButtonDown("Jump"))
         {
                 var bullit = Instantiate(bullitPrefab,
                             GameObject.Find("spawnPointGood").transform.position,
                             Quaternion.identity);
                 bullit.rigidbody.AddForce(transform.forward * 2000);
         }
 
 }
 
 
         {
             transform.position = Vector3(0,4,0);
             gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
             dead = false;
         }
 }
 
 @script RequireComponent(CharacterController)
Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dreamblur · Jul 02, 2011 at 07:15 PM

Your LateUpdate method isn't closed. The method is OnControllerColliderHit, not OnControllerHit. You have that if(dead) line floating there doing nothing. The last block of code does not belong to any scope.

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
avatar image
0

Answer by oliver-jones · Jul 02, 2011 at 07:16 PM

Okay doky, you had a few } in the wrong place, and also - I think you were missing an else statement towards the end. But here it is - with no errors:

 var speed = 3.0;
 var rotateSpeed = 3.0;
 
 //Shooting
 var bullitPrefab:Transform;
 
 //Dying
 private var dead = false;
 
 //Getting Hit
 var tumbleSpeed = 800;
 var decreaseTime = 0.01;
 var decayTime = 0.01;
 static var gotHit = false;
 private var backup = [tumbleSpeed, decreaseTime, decayTime];
 
 function LateUpdate(){
     if(dead){
         if(gotHit){
             if(tumbleSpeed < 1){
                 //we're not hit anymore... reset and get back in the game!
                 tumbleSpeed = backup[0];
                 decreaseTime = backup[1];
                 decayTime = backup[2];
                 gotHit = false;
             }
             else{
                 //we're hit! Spin our character around
                 transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
                 tumbleSpeed = tumbleSpeed-decreaseTime;
                 decreaseTime += decayTime;
             }
         }
     }
 }
 
 function OnControllerHit (hit : ControllerColliderHit){
         if(hit.gameObject.tag == "fallout"){
                 dead = true; //the error is on this line, please help!
                 //subtract life here
                 HealthControl.LIVES -= 1;
         }
 
         if(hit.gameObject.tag == "enemyProjectile"){
                 gotHit = true;
         }
 }
 
 function Update () { 
     var controller : CharacterController = GetComponent(CharacterController);
 
      // Rotate around y - axis
     transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
     var forward = transform.TransformDirection(Vector3.forward);
     var curSpeed = speed * Input.GetAxis ("Vertical");
     controller.SimpleMove(forward * curSpeed);
 
     if(Input.GetButtonDown("Jump")){
         var bullit = Instantiate(bullitPrefab,
         GameObject.Find("spawnPointGood").transform.position,Quaternion.identity);
         bullit.rigidbody.AddForce(transform.forward * 2000);
     }
     else{
         transform.position = Vector3(0,4,0);
         gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
         dead = false;
     }
 }
 
 @script RequireComponent(CharacterController)
Comment
Add comment · Show 1 · 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
avatar image youngtraffords96 · Jul 02, 2011 at 07:56 PM 0
Share

This removed my errors, but now when I try to enter play mode, my character is stuck in midair.

avatar image
0

Answer by GuyTidhar · Jul 02, 2011 at 07:24 PM

 var speed = 3.0;
 var rotateSpeed = 3.0;
 

 //Shooting
 var bullitPrefab:Transform;
 
 //Dying
 private var dead = false;
 
 //Getting Hit
 var tumbleSpeed = 800;
 var decreaseTime = 0.01;
 var decayTime = 0.01;
 
 static var gotHit = false;
 
 private var backup = [tumbleSpeed, decreaseTime, decayTime];
 
 function LateUpdate()
 {
         if(dead)
             if(gotHit)
             {
                     if(tumbleSpeed < 1)
                     {
                             //we're not hit anymore... reset and get back in the game!
                             tumbleSpeed = backup[0];
                             decreaseTime = backup[1];
                             decayTime = backup[2];
                             gotHit = false;
                     }
                     else
                     {
                             //we're hit! Spin our character around
                             transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
                             tumbleSpeed = tumbleSpeed-decreaseTime;
                             decreaseTime += decayTime;
                     }
             }
 }
 
 function OnControllerHit (hit : ControllerColliderHit) //onTriggerEnter : collider 
 {
         if(hit.gameObject.tag == "fallout")
         {
                 dead = true; //the error is on this line, please help!
                 //subtract life here
                 HealthControl.LIVES -= 1;
                 // Is LIVES a static variable of HealthControl? If not, this will not compile
         }
 
         if(hit.gameObject.tag == "enemyProjectile")
         {
                 gotHit = true;
         }
 }
 
 
 function Update () 
 { 
         var controller : CharacterController = GetComponent(CharacterController);
 
         // Rotate around y - axis
         transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
         var forward = transform.TransformDirection(Vector3.forward);
         var curSpeed = speed * Input.GetAxis ("Vertical");
         controller.SimpleMove(forward * curSpeed);
 
         if(Input.GetButtonDown("Jump"))
         {
                 var bullit = Instantiate(bullitPrefab,
                             GameObject.Find("spawnPointGood").transform.position,
                             Quaternion.identity);
                 bullit.rigidbody.AddForce(transform.forward * 2000);
 
 // What was the purpose of these {}?
 /*                
 
         }
 {
         {
 */
 
 // I removed them, but I do not know what was the reason they were here for...
             transform.position = Vector3(0,4,0);
             gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
             dead = false;
         }
 }
 
 @script RequireComponent(CharacterController)
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
avatar image
0

Answer by aldonaletto · Jul 02, 2011 at 07:54 PM

It seems you've mixed parts of several scripts in one single code, but in the wrong places! It looks like a Frankenstein with a leg and one arm replaced by the Tornado Twins heads! There were several answers here, but nobody (me included) seems to know how to solve the puzzle.
Well, let's try to bring some order to the chaos: that lost if (dead) at the beginning seems to be part of the equally lost lines at the end - they seem to form a re-spawn code intended to bring the character back to life. Supposing it's true, the whole script is:

 //Moving Around
 var speed = 3.0;
 var rotateSpeed = 3.0;
 //Shooting
 var bullitPrefab:Transform;
 //Dying
 private var dead = false;
 //Getting Hit
 var tumbleSpeed = 800;
 var decreaseTime = 0.01;
 var decayTime = 0.01;
 static var gotHit = false;
 private var backup = [tumbleSpeed, decreaseTime, decayTime];
 
 function LateUpdate()
 {
     if(gotHit)
     {
         if(tumbleSpeed < 1)    
         {
                 //we're not hit anymore... reset and get back in the game!
                 tumbleSpeed = backup[0];
                 decreaseTime = backup[1];
                 decayTime = backup[2];
                 gotHit = false;
         }
         else {
                 //we're hit! Spin our character around
                 transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
                 tumbleSpeed = tumbleSpeed-decreaseTime;
                 decreaseTime += decayTime;
         }
     }
 }
 
 function OnControllerColliderHit (hit : ControllerColliderHit) 
 {
         if (hit.gameObject.tag == "fallout"){
             dead = true; 
             //subtract life here
             HealthControl.LIVES -= 1;
         }
         if (hit.gameObject.tag == "enemyProjectile"){
             gotHit = true;
         }
 }
 
 function Update () {
 
         var controller : CharacterController = GetComponent(CharacterController);
 
         // Rotate around y - axis
         transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
         var forward = transform.TransformDirection(Vector3.forward);
         var curSpeed = speed * Input.GetAxis ("Vertical");
         controller.SimpleMove(forward * curSpeed * Time.deltaTime);
 
         if(Input.GetButtonDown("Jump")) 
         {
             var bullit = Instantiate(bullitPrefab,
                         GameObject.Find("spawnPointGood").transform.position,
                         Quaternion.identity);
             bullit.rigidbody.AddForce(transform.forward * 2000);
         }
         if (dead)
         {
             transform.position = Vector3(0,4,0);
             gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
             dead = false;
         }
 }
 
 @script RequireComponent(CharacterController)

I really don't know if this script will do something - you will need other pieces, like a collider tagged fallout, another script called HealthControl.js with an int variable LIVES in there, a bullet prefab tagged enemyProjectile and God-knows-what more, but good luck anyway!

Comment
Add comment · Show 1 · 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
avatar image youngtraffords96 · Jul 02, 2011 at 08:14 PM 0
Share

I have the other pieces, including tags and scripts. Haha. I am actually trying to alter some of the script from a Tornado Twins tutorial. The only thing that I am really changing is the characters. In their tutorial, they made a game with a worm vs turrets. I am am doing a robot vs robot turrets.

The changes you made to the script worked the best out of all so far. The only issue now is when I enter play mode, my character spawns as usual in the correct place. But, from there, all I can make him do is rotate. $$anonymous$$y character will not move back or forward anymore...

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

6 People are following this question.

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

Related Questions

script not working 2 Answers

Script error. Please Help! 4 Answers

BCE0044: expecting (, found 'OnTriggerEnter'. 1 Answer

Assets/NewBehaviourScript.js(10,29): BCE0044: expecting :, found ';'. HELP! 2 Answers

False Errors? BCE0044 expecting :, found ";" 1 Answer


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