How to change isKinematic only in one scene C#
Hello. If I have prefab with checked Is Kinematic how can I change this value in one scene, where I use this prefab? Using the C# script. Could you give me some advice?
Answer by TBruce · Jun 27, 2016 at 01:15 AM
Lets say you have 4 scenes - Level1, Level2, Level3 and Level4. They are indexed 0 through 3. Lets say that you want to uncheck "Is Kinematic" on Level2 only, here are two possible ways
public GameObject myPrefab; // the prefab must have a Ridgidbody attached
GameObject go = (GameObject)Instantiate (myPrefab, transform.position, Quaternion.identity);
Rigidbody rb = go.GetComponent<Rigidbody>();
rb.isKinematic = (SceneManager.GetActiveScene().buildIndex != 1);
or you can do it this way
public Rigidbody myPrefab; // the prefab must have a Ridgidbody attached
Rigidbody rb = (Rigidbody)Instantiate (myPrefab, transform.position, Quaternion.identity);
myPrefab.isKinematic = (SceneManager.GetActiveScene().buildIndex != 1);
Thanks $$anonymous$$ate! That second way solved my problem. :)
I should have also mentioned that ins$$anonymous$$d of
myPrefab.is$$anonymous$$inematic = (Scene$$anonymous$$anager.GetActiveScene().buildIndex != 1);
you can do
myPrefab.is$$anonymous$$inematic = (Scene$$anonymous$$anager.GetActiveScene().name != "Level2");
Your answer
Follow this Question
Related Questions
Masking based on angles 0 Answers
Control the value of an animation with a slider 0 Answers
XML data from an API to a displayable String? 0 Answers
how to implement online leader board to my project? 0 Answers
Teleport 2D Character on TriggerEnter 2 Answers