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 Milojko · Jan 08, 2018 at 06:39 AM · androidscripting problemscripting beginnerrotate object

Working with 2 scripts

Hi all, i am really new to unity and scripting and i am googling for this in last 2 days and i cant find answers. I have a problem with rotating object. I have a cube that i want to rotate constantly. In script that is on cube i have transform.Rotate function and it work great when i place it on void Update but i need to call it from other script with player.GetComponent().rotate();

http://prntscr.com/hxhf07

and here is my problem, when i call it like this it rotate just 1 frame and then stop.I need it to keep rotating. I am sertainly doing something wrong but i just cant figure it out.

Here is script with rotation http://prntscr.com/hxhfam

Thank you for helping me in advance.

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

Answer by khiemngs · Jan 08, 2018 at 07:48 AM

Hi Milojko.

I see the problem you are facing is you don't completely understand how game work.

The game has big loop start from beginning to the end (when close game). Update method runs every frame, so when rotating in Update, it rotates every frame and you get what you want. When you move rotate to another method and call it, it just runs once when you call it.

I guess you want it to rotate if only you call a rotate and it keeps rotate in others frame after it. Try to create a bool to save rotate state.

 bool isRotate = false;
 
 void Update()
 {
     if(isRotate)
     {
         Rotate();
     }
 }
 
 void BeginRotate()
 {
     isRotate = true;
 }
 
 void StopRotate()
 {
     isRotate = false;
 }
 
 void Rotate()
 {
     // Your code here
 }




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 Milojko · Jan 08, 2018 at 09:32 AM 0
Share

Thank you so much man, i am new in unity so i am still learning, you saved me, i just put my code in void BeginRotate and it is working.

bool isRotate = false;

 void Update()
 {
     if (isRotate)
     {
         BeginRotate();
     }
 }

 public void BeginRotate()
 {
     isRotate = true;
     transform.Rotate(0, 0, speed);
     Debug.Log("Radi");
 }

 void StopRotate()
 {
     isRotate = false;
 }

}

avatar image khiemngs Milojko · Jan 08, 2018 at 01:44 PM 0
Share

You are welcome. :D At the beginning, I make the same mistake like that. I suggest you try to find out how basic game work. The game is an animated movie which every frame is rendered by code. :D

avatar image
0

Answer by Ginxx009 · Jan 08, 2018 at 06:56 AM

Is this what you wanted.

1st script

 void RotateObject(){
   //transform.Rotate function
 }

2nd script

 public firstScript; //drag your first script here
 
 void Update(){
    firstScript.GetComponenent<NameOfTheFirstScript>(). RotateObject();
 }
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 Milojko · Jan 08, 2018 at 07:26 AM 0
Share

Thank you so much for helping but it isnt what i need, i need to call it when i swipe my finger up and i cant add void Update in that line. In my case it will do it just one frame and then stop

avatar image Ginxx009 Milojko · Jan 08, 2018 at 07:30 AM 0
Share

So put it inside the Input.GetTouch().

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

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

Player Prefs Dosen't work on android 0 Answers

Unity Editor Freezes- Help! Urgent! 1 Answer

How to implement listeners in unity3d android plugin? 0 Answers

how to make a detect rotation script for negative rotation too 2 Answers

Controls work fine on PC, but not on android phone. 0 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