- Home /
Problem is not reproducible or outdated
Animation Reset
Hello there, i have restart button in my game, and that button functions working perfectly i reset all variables(all scenes). If i press restart my variables and position getting zero, but my animated objects not working. How cant i reset that thing.
-Prasanna
Answer by sumeetkhobare · Apr 28, 2014 at 11:15 AM
Try writing
animation.Stop();
in your reset button function .
Also Share ur code snippet and your gameobject screenshots
Mark this as solved if the question is solved.
thanks for your reply, already tried this. Its not working.
I added the codes below,
using UnityEngine;
using System.Collections;
public class Dice : $$anonymous$$onoBehaviour
{ private GUIStyle testStyle = new GUIStyle (); public GUIStyle ButtonGUI = new GUIStyle(); public static bool showButton = false; public static int Value, Counter = 0; public Texture2D DiceRoll = null;
// Turn Based...
public Texture2D Turn_One, Turn_Two;
public static bool Roll = true, Check = true;
public AudioClip RollSound;
public void OnGUI()
{
Vector3 scale;
float ResolutionX = 1280;
float ResolutionY = 800;
scale.x = (float)Screen.width/ResolutionX;
scale.y = (float)Screen.height/ResolutionY;
scale.z = 1;
$$anonymous$$atrix4x4 sv$$anonymous$$at = GUI.matrix;
GUI.matrix = $$anonymous$$atrix4x4.TRS(new Vector3(0,0,0),Quaternion.identity,scale);
if(Counter %2 == 0)
{
if(Roll == true)
{
GUI.Box(new Rect(0, 490, Turn_One.width, Turn_One.height),Turn_One, testStyle);
}
Check = true;
}
else if(Counter %2 == 1)
{
if(Roll == true)
{
GUI.Box(new Rect(1050, 490, Turn_Two.width, Turn_Two.height),Turn_Two, testStyle);
}
Check = false;
}
if(showButton == true)
{
if(GUI.Button(new Rect(550, 710, DiceRoll.width, DiceRoll.height),DiceRoll, ButtonGUI))
{
audio.clip = RollSound;
audio.Play();
if(Roll)
{
Value = Random.Range(1,7);
//Single Player
if(Check == true)
{
Egg$$anonymous$$ove.BoxNumber = Value + Egg$$anonymous$$ove.CurrentBox;
Egg$$anonymous$$ove.$$anonymous$$oveClick = true;
Egg$$anonymous$$ove.Condition = true;
}
//Second player...
else if(Check == false)
{
SecondPlayer.BoxNumber = Value + SecondPlayer.CurrentBox;
SecondPlayer.$$anonymous$$oveClick = true;
SecondPlayer.Condition = true;
}
//Debug.Log("Dice On");
switch(Value)
{
default:
case 1:
animation.Play("One");
break;
case 2:
animation.Play("Two");
break;
case 3:
animation.Play("Three");
break;
case 4:
animation.Play("Four");
break;
case 5:
animation.Play("Five");
break;
case 6:
animation.Play("Six");
break;
}
if(Value != 1 && Value != 5)
{
Counter += 1;
}
}
else if(Roll == false)
{
//Debug.Log("Dice Off");
animation.Stop("One");
animation.Stop("Two");
animation.Stop("Three");
animation.Stop("Four");
animation.Stop("Five");
animation.Stop("Six");
audio.Stop();
}
showButton = false;
}
}
else if(showButton == false)
{
showButton = true;
}
}
}
this script is working fine..
using UnityEngine;
using System.Collections;
public class Pause : $$anonymous$$onoBehaviour
{ public bool IsPaused = false; public bool ShowButton = true; public bool Exit$$anonymous$$enuButton = false;
private GUIStyle TestStyle = new GUIStyle ();
public Texture2D PauseTexure = null;
public Texture2D PauseScreen = null;
public Texture2D ResumeTexture = null;
public Texture2D $$anonymous$$enuTexture = null;
public Texture2D ExitTexture = null;
//GUI $$anonymous$$atrix
public void OnGUI()
{
Vector3 scale;
float ResolutionX = 1280;
float ResolutionY = 800;
scale.x = (float)Screen.width/ResolutionX;
scale.y = (float)Screen.height/ResolutionY;
scale.z = 1;
$$anonymous$$atrix4x4 sv$$anonymous$$at = GUI.matrix;
GUI.matrix = $$anonymous$$atrix4x4.TRS(new Vector3(0,0,0),Quaternion.identity,scale);
if (ShowButton == true)
{
if (GUI.Button (new Rect (1200, 15, PauseTexure.width, PauseTexure.height), PauseTexure, TestStyle))
{
GamePlay ();
ShowButton = false;
Dice.Roll = false;
}
}
else if (ShowButton == false)
{
GUI.Box(new Rect (450, 200, PauseScreen.width, PauseScreen.height), PauseScreen, TestStyle);
if (GUI.Button (new Rect (610, 300, ResumeTexture.width, ResumeTexture.height), ResumeTexture, TestStyle))
{
GamePause ();
ShowButton = true;
Dice.Roll = true;
}
if (GUI.Button (new Rect (620, 350, $$anonymous$$enuTexture.width, $$anonymous$$enuTexture.height), $$anonymous$$enuTexture, TestStyle))
{
Application.LoadLevel ("$$anonymous$$ain $$anonymous$$enu");
}
if (GUI.Button (new Rect (605, 400, ExitTexture.width, ExitTexture.height), ExitTexture, TestStyle))
{
Application.LoadLevel("Exit");
}
}
}
public void GamePause()
{
if (IsPaused == true)
{
Time.timeScale = 1;
IsPaused = false;
}
}
public void GamePlay()
{
if(IsPaused == false)
{
Time.timeScale = 0;
IsPaused = true;
}
}
}
In this script i need to restart all other animation in $$anonymous$$enu button
$$anonymous$$y animation.stop(); is working fine, but i need to restart that animation from start when i pressed that menu button.. I hope u understand the Problem
try
animation.Rewind("aniamtion_name");
write this command somewhere in the start() or awake function() in your scene.. so when you load or restart it again, it will rewind and then when you actually play it, it will start from beginning..
also, do one extra thing by following this: 1. select your gameobject which has animation component. 2. hit Ctrl + 6 or open the animation window from 'Window' menu at the top . 3. now, at the topleft, you show be able to find out your 'animation_name' select it. 4. at the bottom-left, you could find an option of how the animation should play. like, Default,Loop,Once,ClampedForever,etc. 5. make sure this option is set to Once, at least not to ClampedForever. the clamped option maintains the position of your animation seek cursor. for more details check the animation script reference and manual reference at unity's documentation.
Thanks for that Tip, i tried that but again i got the same problem.
Follow this Question
Related Questions
Making an animation play when you press down 2 keys 1 Answer
A node in a childnode? 1 Answer
Blender Animations not working properly. 1 Answer
Can I make animations snap to a frame? 1 Answer
my animation script does not work 0 Answers