• 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 mohd-ma · Sep 06, 2014 at 10:32 PM · functionfunctionscall

v.important : Choose one from functions to execute !!

Hello guys , i have two functions (RotateRight & RotateLeft), please how i can choose one of two functions to execute one of them randomly when the script executing !!

i try this code :

 var functions = [RotateRight,RotateLeft];
 
 
 function Update(){
 if(Timer1>=2){
 functions[Random.Range(0,functions.Length)]();
 }
 if(Timer1>=5){
  TranslateBack = false ; 
  TasadomDone = true ;
  Timer1=0 ;
 }
 
 }


the problem here that the script execute this : functions[Random.Range(0,functions.Length)](); and still choose between the two functions without execute the next Lines . where id the problem here ??! i want every time choose one of two functions only , then executing the next lines . sorry for question , i,m a beginner , and sorry for my english :(

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
0

Answer by orb · Sep 08, 2014 at 09:35 AM

You're checking if the number is larger than 1, followed by checking if the number is larger than 4. Both will be true at the same time if the second is true. You should either reverse the order (check for the largest numbers first).

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

23 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

Related Questions

How do I call a function containing a while loop, inside the update function? 2 Answers

Calling a from another script c# 2 Answers

How is calling a function from a button click handled internally? 1 Answer

Issues using NotificationCenter to pass value from one object to another 1 Answer

Function being called when statement untrue? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges