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
0
Question by Zcxvnbads · Apr 24, 2011 at 08:51 PM · bce0034

Error: "Expressions in statements must only be executed for their side-effects"

Help!

im using the tornadotwins's tutorial on how to make a video game #5.

And i'm almost done, but i got an error

Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.js(94,77): BCE0034: Expressions in statements must only be executed for their side-effects.

/ ThirdPersonWalker.js

// this script adds two things to the default FPS walker // - It adds movement forward by holding down both mouse keys // - and it adds auto animation changing between idle, walk and run // After adding this script to your controller, drag the character model to Target

var speed = 6.0; // standard running speed var walkSpeed = 8; // walk speed adjust both for your charcter so feet don't slide on ground var jumpSpeed = 8.0; var gravity = 20.0; var Character : Transform; var bullitPrefab:Transform;

private var moveDirection = Vector3.zero; private var grounded : boolean = false; // a flag to determine idle vs walking/running (so animations do not get started over and over) private var walking : boolean = false; // a flag to init idle animation at beginning private var startup : boolean = true; // a flag to determine walking vs running private var running : boolean = true;

function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

// if both mouse buttons are down, move forward if (Input.GetMouseButton(0) && Input.GetMouseButton(1)) { moveDirection.z = 1; }

moveDirection = transform.TransformDirection(moveDirection); if(running == true){ moveDirection = speed; } else { moveDirection = walkSpeed; }

if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; }

// auto toggle between idle and walking animations - based on run / walk switch if(Character){ // toggle between walk and run with <left shift> R if(Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.R)){ if(running == true) { running = false; if(walking == true) Character.animation.CrossFade("walk"); } else { running = true; if(walking == true) Character.animation.CrossFade("run"); } } if(startup == true){ startup = false; Character.animation.Play("idle"); } if((moveDirection == Vector3.zero)&&(walking == true)){ walking = false; Character.animation.CrossFade("idle"); } else { if((moveDirection != Vector3.zero)&&(walking == false)){ walking = true; if(running == true){ Character.animation.CrossFade("run"); } else { Character.animation.CrossFade("walk"); } } } } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime;

// Move the controller var controller : CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0;

if(Input.GetButtonDown("Jump")) { var bullit = Instantiate (bullitPrefab,
GameObject.Find("spawnPoint").transform.position,
Quaternion.identity) ; bullit.rigidbody.AddForce(transform.forward 5000); } }
GameObject.Find("spawnPoint").transform.position; (Quaternion.identity) ; bullitPrefab.rigidbody.AddForce(transform.forward
5000);

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AngryOldMan · Apr 24, 2011 at 09:12 PM

if you keep your code neat and tidy then these problems will be much easier to spot

// ThirdPersonWalker.js

// this script adds two things to the default FPS walker // - It adds movement forward by holding down both mouse keys // - and it adds auto animation changing between idle, walk and run // After adding this script to your controller, drag the character model to Target

var speed = 6.0; // standard running speed var walkSpeed = 8; // walk speed adjust both for your charcter so feet don't slide on ground var jumpSpeed = 8.0; var gravity = 20.0; var Character : Transform; var bullitPrefab:Transform;

private var moveDirection = Vector3.zero; private var grounded : boolean = false; // a flag to determine idle vs walking/running (so animations do not get started over and over) private var walking : boolean = false; // a flag to init idle animation at beginning private var startup : boolean = true; // a flag to determine walking vs running private var running : boolean = true;

function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); // if both mouse buttons are down, move forward if (Input.GetMouseButton(0) && Input.GetMouseButton(1)) { moveDirection.z = 1; } moveDirection = transform.TransformDirection(moveDirection);

     if(running == true)
     {
         moveDirection *= speed;
     }
     else
     {
         moveDirection *= walkSpeed;
     }

     if (Input.GetButton ("Jump"))
     {
         moveDirection.y = jumpSpeed;
     }

     // auto toggle between idle and walking animations - based on run / walk switch
     if(Character)
     {
         // toggle between walk and run with &lt;left shift&gt; R
         if(Input.GetKey(KeyCode.LeftShift) &amp;&amp; Input.GetKeyDown(KeyCode.R))
         {
             if(running == true) 
             {
                 running = false;
                 if(walking == true) Character.animation.CrossFade("walk");
             } 
             else 
             {
                 running = true;
                 if(walking == true) Character.animation.CrossFade("run");
             }
         }
         if(startup == true)
         {
             startup = false;
             Character.animation.Play("idle");
         }
         if((moveDirection == Vector3.zero)&amp;&amp;(walking == true))
         {
             walking = false;
             Character.animation.CrossFade("idle");
         }
         else 
         {
             if((moveDirection != Vector3.zero)&amp;&amp;(walking == false))
             {
                 walking = true;
                 if(running == true)
                 {
                     Character.animation.CrossFade("run");
                 }
                 else 
                 {
                     Character.animation.CrossFade("walk");
                 }
             }
         }
     }
 }
 // Apply gravity
 moveDirection.y -= gravity * Time.deltaTime;

 // Move the controller
 var controller : CharacterController = GetComponent(CharacterController);
 var flags = controller.Move(moveDirection * Time.deltaTime);
 grounded = (flags &amp; CollisionFlags.CollidedBelow) != 0;

 if(Input.GetButtonDown("Jump"))
 {
     var bullit = Instantiate (bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity) ;
     bullit.rigidbody.AddForce(transform.forward * 5000);
 }

}

//this is the bit your getting errors in, not sure what you are doing with this bit? /
GameObject.Find("spawnPoint").transform.position; (Quaternion.identity) ; bullitPrefab.rigidbody.AddForce(transform.forward
5000); */

The reason you are getting errors is because this section isnt in a function. I can't figure out what you are trying to do with it so I've just blanked it out.

Comment
Add comment · Show 2 · 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 Joshua · Apr 24, 2011 at 09:14 PM 0
Share

Nice work. I just saw that chunk of jibberish and though never $$anonymous$$d xD

avatar image AngryOldMan · Apr 24, 2011 at 10:07 PM 0
Share

same here but OCD dictated that I had to tidy it :(

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

No one has followed this question yet.

Related Questions

Whats wrong with this script? 1 Answer

Application.Quit 2 Answers

"Expressions in statements must only be executed for their side effects." ERROR. 3 Answers

Get object name from raycast. 1 Answer

Need some help with my Gravity Gun, New to Scripting. 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