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 Mohammadjavad · Nov 10, 2011 at 07:53 PM · dice

how can I change the scene after throwing a dice??

Hello.I am using a dice in my game.I want to change my scene after throwing this dice. But I can't do this properly because I couldn't find this line (Application.LoadLevel("firstLevel"); ) place in my code. After throwing dice , it has some rotation on the plane. I want to change scene aftar these rotations. My code :

public var faceValue = 0;

function OnTriggerEnter( other : Collider ) {

dieGameObject = GameObject.Find("SixSidedDie");

dieValueComponent = dieGameObject.GetComponent("DieValue");

dieValueComponent.currentValue = faceValue;

Debug.Log(faceValue);

Application.LoadLevel("firstLevel");

}

Main problem is this : with this codes when dice and plane have a collision with eachother scene is changed but I want this change happens after dice stops on the plane.

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
1

Answer by DaveA · Nov 10, 2011 at 08:04 PM

You will need to know when the dice are in motion, and when they have stopped. How are you moving the dice? In any case, in an Update function, get the velocity (and time). After a set amount of time has passed after you detect that their velocity(s) are zero, then call Application.LoadLevel.

Comment
Add comment · Show 5 · 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 Mohammadjavad · Nov 10, 2011 at 08:28 PM 0
Share

These are moving codes :

public var currentValue = 0;

var power : float = 500.0;

function Start () {

transform.rotation=Random.rotation;

rigidbody.AddForce(Vector3(0,0,power));

}

function Update() {

 transform.Rotate(Vector3.right * Time.deltaTime);

 transform.Rotate(Vector3.up * Time.deltaTime,Space.World);

 dieTextGameObject = GameObject.Find("DieText");
 text$$anonymous$$eshComponent = dieTextGameObject.GetComponent     ("Text$$anonymous$$esh");

text$$anonymous$$eshComponent.text = currentValue.ToString();

}

function FixedUpdate () {

  rigidbody.AddTorque (Vector3.up * 1);


}

You told me -> (You will need to know when the dice are in motion, and when they have stopped) . But how can I know that ? It's unpredictable.

avatar image DaveA · Nov 10, 2011 at 09:22 PM 0
Share

In Update, check rigidbody.velocity for having magnitude zero: http://unity3d.com/support/documentation/ScriptReference/Rigidbody-velocity.html

avatar image Mohammadjavad · Nov 11, 2011 at 03:29 AM 0
Share

Thanks a million , You are right. I did it :)

avatar image Kehos · Aug 21, 2012 at 07:18 PM 0
Share

How did you fix it? I'm having a lot of trouble with this exactly thing and I'm unable to solve this: the velocity of my rigidbody is never 0 even if the object isn't moving

avatar image DaveA · Aug 21, 2012 at 10:28 PM 0
Share

That's odd, so maybe you can check if the velocity magnitude is < .0001 or something

avatar image
0

Answer by jabad · Nov 10, 2011 at 10:30 PM

The best way to detect whether the two dice have stop moving is to put a character controller on each one. a character controller has a velocity variable that you can check whether or not that object is moving.

So if you check when the two velocities have hit zero then you can load your new level. good luck.

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 DaveA · Nov 10, 2011 at 11:37 PM 0
Share

His code indicates rigidbody, which is why I suggested check velocity on them.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to rotate a dice to a final angle ? 1 Answer

Dice roll - ToString text placement using GUILayout 0 Answers

make dice game for two players 1 Answer

Needing a hint about tossing dices and using their value 1 Answer

How can I throw an object using accelerometer or tilt? 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