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 RussianBsack · Feb 20, 2015 at 12:26 PM · gameobjectinstantiatequaternionclonewalls

Rotate a cloned object with key press

I'm trying to rotate a cloned object once it is spawned but i'm having difficulty and cant find any information about how to do this.

For example, i spawn a wall, once i press "R" it rotates to 90 degrees along its x axis. Or, if you press "R" it transforms to 90 and then you put it down? I just need an understanding on how to do this. I'm unfamiliar with Quaternions is this the problem?? The code i have doesn't seem to be working.

         if (Input.GetMouseButtonDown(0))
         {
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             // Storage point for the Ray
             RaycastHit hit;
 
             if (Physics.Raycast(ray, out hit))
             {
                 // Assigning the point its variable
                 endPoint = hit.point;
 
 
                 GameObject clone;
 
                 // Clone the objects and spawn them in the game 'world'
                 clone = Instantiate(items[i], endPoint, items[i].transform.rotation) as GameObject;
 
                 if (Input.GetKey(KeyCode.R))
                 {
                     clone.transform.Rotate(0, 90, 0);
                     Debug.Log("Rotating Object");
                 }
             }
 
         }
Comment
Add comment · Show 3
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 kbaloch · Feb 20, 2015 at 01:36 PM 0
Share

where is the problem ? in object rotation ?

avatar image RussianBsack · Feb 20, 2015 at 01:58 PM 0
Share

The object isn't rotating when i press R, maybe creating a new transform function will work?

avatar image kbaloch · Feb 20, 2015 at 02:16 PM 0
Share

try transform.Rotate.y = 90;

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by HarshadK · Feb 20, 2015 at 02:03 PM

As per your code the R key has to be pressed down in the same frame when the left mouse button is clicked.

Just take out the code that handles the R key press outside Mouse Button press check and change your code accordingly.

You need to declare your 'clone' gameobject to be outside Update in order for the object cloned to persist between multiple frame executions. Then on R keypress check if clone is null or not and if not null you can rotate it with the current rotation code. Also once the object is placed on the ground just set your clone object to null in order to avoid that object being rotated even after it is placed on the ground.

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 RussianBsack · Feb 20, 2015 at 02:06 PM 0
Share

Thank you, works great! Only just realized that it was because it was within the button down function.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Clone Selector 1 Answer

Instantiate GameObject cloned into wrong position. 1 Answer

Assign an instantiated GameObject? 1 Answer

Reference an Instance of an Object?C# 1 Answer

Variable being shared between clones 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