- Home /
Cloth problem
Hi!
I have a problem when I pause my game with an cloth object in the level. I can pause the game but when I resume the game it freezes for some seconds and then I get 2 errors and the cloth in level disappears.
PauseScript.js
var paused : boolean = false;
var Target1 : GameObject;
var Target2 : GameObject;
var Target3 : GameObject;
var texture : GUITexture;
var pause : AudioClip;
function Update ()
{
Pause();
}
function Pause()
{
if(Input.GetKeyDown("escape") && paused == false)
{
AudioSource.PlayClipAtPoint(pause, transform.position);
//yield WaitForSeconds(0.3);
paused = true;
Time.timeScale = 0;
savedTimeScale = Time.timeScale;
doPauseWindow = true;
Time.timeScale = 0;
AudioListener.volume = 0;
Target1.GetComponent("MouseLook").enabled = false;
Target2.GetComponent("MouseLookCamera").enabled = false;
Target3.GetComponent("CrosshairSimple").enabled = false;
gameObject.Find("PausetextureBlack").guiTexture.enabled = true;
Screen.showCursor = true;
Screen.lockCursor = false;
texture.enabled = true;
}
else if(Input.GetKeyDown("escape") && paused == true) {
paused = false;
Time.timeScale = 1;
AudioListener.volume = 1;
AudioSource.PlayClipAtPoint(pause, transform.position);
Target1.GetComponent("MouseLook").enabled = true;
Target2.GetComponent("MouseLookCamera").enabled = true;
Target3.GetComponent("CrosshairSimple").enabled = true;
gameObject.Find("PausetextureBlack").guiTexture.enabled = false;
Screen.showCursor = false;
Screen.lockCursor = true;
texture.enabled = false;
}
}
Error
Answer by jheiling · Sep 18, 2013 at 02:42 PM
Waiting for one frame before enabling the cloth again worked for me.
Sorry, that wasn't clear at all... disable the cloth component on pause (it should still get rendered, but without cloth simulation), then enable it again one frame after continuing. Enabling / disabling SkinnedCloth can look quite ugly though, so maybe you should use SetEnabledFading.
Thanks, that worked! :D Added a cloth variable and then added this line on the pause event "cloth.enabled = false;"
Answer by evenwang35 · Mar 28, 2014 at 06:46 AM
hello, i am faced with the same question, my clothes disappear when i unpause the game. i used GameObject.Find("tp1").GetComponent(InteractiveCloth).enabled = false; before i pause the game, but it doesnt work. is there anything wrong with my codes?
Add a cloth variable ins$$anonymous$$d and add the line "cloth.enabled = false". After that you can drag and drop the cloth object to the script in the inspector
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unity is stuck on White screen every time i open it. 1 Answer
Inventory system Help 2 Answers
Problem with transform.Rotate 1 Answer
Destroyable barrier 1 Answer