Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity control physics of multiple simulation

//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 :: C# is folder 
Csharp :: go to the corresponding brace visual studio C# 
Csharp :: how to validate decimal number with percision of (25, 4) iin c# 
Csharp :: Compiling C# Example 
Csharp :: unity raycast hit child object 
Csharp :: six simple machines labeled 
Csharp :: static {} 
Csharp :: player ToJson unity 
Csharp :: get first and last item list c# 
Csharp :: C# Project File Create 
Csharp :: unity using tmpro not working 
Csharp :: split array into pieces of x length c# 
Csharp :: vb.net tostring numeric format string 
Csharp :: set main camera unity 
Csharp :: c# string contain double quote 
Csharp :: c# String Uppercase and Lowercase method 
Csharp :: thread c# 
Csharp :: unity trigger not detecting collision 
Csharp :: out variable in c# 
Csharp :: How to make a drawer in unity 
Csharp :: read administrator account remote machine C# 
Csharp :: black lives matter update arsenal 
Html :: calling javascript file in html 
Html :: how to center text in svg 
Html :: html input not editable 
Html :: python jupyter markdown color 
Html :: html dot symbol 
Html :: js import web3 cdn 
Html :: read only html 
Html :: sample html file 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =