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 Jaidan · Feb 22, 2015 at 03:59 PM · error messagenot working

Why isnt my code working? C# [NOOB]

I need to know why my code is not working:

 using UnityEngine;
 using System.Collections;
 
 public class ShipController : MonoBehaviour{
 
     public float turnspeed = 5f;
     public float speed = 5f;
     public float trueSpeed = 0f;
     public float strafeSpeed = 5f;
     
     void Update () {
         
         float roll = Input.GetAxis ("Roll");
         float pitch = Input.GetAxis ("Pitch");
         float yaw = Input.GetAxis ("Yaw");
         float strafe = Vector3 (Input.GetAxis ("Horizontal") * strafeSpeed * Time.deltaTime, Input.GetAxis ("Vertical") * strafeSpeed * Time.deltaTime, 0);
         
         float power = Input.GetAxis ("Power");
         
         if (trueSpeed < 10f && trueSpeed > -3f) {
             trueSpeed += power;
         }
         if (trueSpeed > 10f) {
             trueSpeed = 9.99f;    
         }
         if (trueSpeed < -3f) {
             trueSpeed = -2.99f;    
         }
         if (Input.GetKey ("backspace")) {
             trueSpeed = 0;
         }
         
         rigidbody.AddRelativeTorque (pitch * turnspeed * Time.deltaTime, yaw * turnspeed * Time.deltaTime, roll * turnspeed * Time.deltaTime);
         rigidbody.AddRelativeForce (0f, 0f, trueSpeed * speed * Time.deltaTime);
         rigidbody.AddRelativeForce (strafe);
     }
 }

Errors:

Assets/ShipController.cs(16,32): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

Assets/ShipController.cs(35,27): error CS1502: The best overloaded method match for UnityEngine.Rigidbody.AddRelativeForce(UnityEngine.Vector3)' has some invalid arguments Assets/ShipController.cs(35,27): error CS1503: Argument #1' cannot convert float' expression to type UnityEngine.Vector3'

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
Best Answer

Answer by tanoshimi · Feb 22, 2015 at 04:06 PM

 float strafe = Vector3 (Input.GetAxis ("Horizontal") * strafeSpeed * Time.deltaTime, Input.GetAxis ("Vertical") * strafeSpeed * Time.deltaTime, 0);

should be:

 Vector3 strafe = new Vector3 (Input.GetAxis ("Horizontal") * strafeSpeed * Time.deltaTime, Input.GetAxis ("Vertical") * strafeSpeed * Time.deltaTime, 0);
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 Jaidan · Feb 22, 2015 at 04:17 PM 0
Share

Thank you

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

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

Related Questions

Rigidbody2D just doesnt work :| 2 Answers

Not booting past the project selection screen 0 Answers

trying to make a projectile move towards mouse position but but im getting an error anyone able to help 1 Answer

I keep getting these two compiler errors when I open Unity, does anyone have a fix for this? 1 Answer

Issues with script in unity 5.4.5p5 and VS 2017 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