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 isaiastheweezerd · Oct 23, 2017 at 12:23 AM · scripting problemtransformrotatefix

Help with Rotating code?

Hi! I'm new to unity and i'm learning how to use C Sharp coding language, currently in my tech demo the player Holds a knife, (A child to the first person camera) and i'm making a script attached to the knife game object, in this script i want the player to use Left click on their mouse to "Rotate" the knife and simulate a attacking motion, here is the script i wrote,

 void Update () {
     if (Input.GetKey(KeyCode.Mouse0)) {
         transform.Rotate(Vector3.right) = true;
     } else {
         transform.Rotate(Vector3.right) = false;
     }

} }

The error with this script: Assets/My assets/Scripts/Knife_Hit.cs(9,14): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer

What does this mean? could someone fix this script and tell me how its done, thanks. :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MezFo · Oct 23, 2017 at 02:29 AM

@isaiastheweezerd It looks like you need to use a speed variable to tell it to move instead of true/false.

Try adding a float to you script called speed and write it like this (below).

 public float speed = 1f;
 
 void Update () {
      if (Input.GetKey(KeyCode.Mouse0)) {
          transform.Rotate(Vector3.right * speed);
      } else {
          transform.Rotate(Vector3.right * 0);
      }

However you will probably want to look into slerping for a knife swing attack. With simple rotation it will be hard to get the knife back to it's original position when not holding down mouse. With slerp you can make it rotate towards position x while key is down and automatically rotate back to original position when key is up.

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 Akvavit · Oct 23, 2017 at 05:22 AM 0
Share

} else { transform.Rotate(Vector3.right * 0); } Does nothing.

} else { transform.rotation = Quaternion.identity; }

maybe?

avatar image
0

Answer by adipatil3517 · Oct 23, 2017 at 05:06 AM

void Update () { if (Input.GetKey(KeyCode.Mouse0)) { transform.Rotate(Vector3.right) ; } }

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

139 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 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 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 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 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 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 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

How rotate only z axis of Gameobject (2D) 1 Answer

How to make a cube topple?(with accuracy) 1 Answer

Will not rotate when going different speed? 1 Answer

transform.Rotate(Vector3.up ... not working 0 Answers

How do I make gameObject.transform.rotation.z equal to a set float value? 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