Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity stop physics

//if you have multiple scenes running concurrently and want to stop some of them
bool isRunning = false;
Scene _currScene;
PhysicsScene _physicsScene;

void start()
{
  //first disable auto simualtion and control 
  //control when do you want the simulation to 
  //run by a boolean
   Physics.autoSimulation = false;
   isRunning = true;
  //get the physics scene that you want it to be running 
  _currScene = SceneManager.GetActiveScene();
  _physicsScene = _currScene.GetPhysicsScene();
  // a boolean to stop the physcis in a scene
 
}
void FixedUpdate()
{
  if (_currScene.IsValid() && isRunning )
    {
      _physicsScene.Simulate(Time.deltaTime);
    }
}
void disablePhysics(){ isRunning = false;}
void enablePhysics(){ isRunning = true;}

// another way to stop the physics is by changing the time scale from 1 to 0 
void disablePhysics(){ Time.timeScale = 0;}
void enablePhysics(){ Time.timeScale = 1;}
// remember that anything that moves in the scene using methods that you coded
//must be linked to Time.deltaTime so you don't end up with some objects out of sync
//check the source for more info
Comment

PREVIOUS NEXT
Code Example
Csharp :: Unlit shader get the direction of camera UNity 
Csharp :: how to get length of okobjectresult c# 
Csharp :: c# get file author 
Csharp :: drawing default serializedproperty unity 
Csharp :: c# multiplicate char 
Csharp :: Get location in Xamarin - NAYCode.com 
Csharp :: convert video to byte array c# 
Csharp :: vb.net delete folder if exists 
Csharp :: c# unit test exception using try catch 
Csharp :: c# array to label 
Csharp :: write last line txt file c# 
Csharp :: use c#9 
Csharp :: Palindromic substrings 
Csharp :: mysql restore backup from multiple files 
Csharp :: display image script unity 
Csharp :: asp.net core update-database specify environment 
Csharp :: c sharp async 
Csharp :: c# return two values 
Csharp :: list to ilist c# 
Csharp :: c# 2d arrays 
Csharp :: get list of months and year between two dates c# 
Csharp :: How to invoke an AWS Lambda function asynchronously 
Csharp :: list contains type c# 
Csharp :: EF .NET4 INSERT IMPROVE PERFORMACE 
Csharp :: can object change color when collided with particles unity 
Csharp :: Delayed respawn timer 
Csharp :: difference between iqueryable and ienurable 
Csharp :: pass viewbag selectlistitem to razor 
Csharp :: messagebox error c# 
Csharp :: entity framework linq join 2 tables c# 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =