Physics Material 2D Bounciness Does Not Revert After Playtime!
GameObject[] Balls;
bool FinalTrigger = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (FinalTrigger == true) {
ModifiedBalls();
}
}
void OnTriggerEnter2D (Collider2D coll){
FinalTrigger = true;
}
void ModifiedBalls(){
Balls = GameObject.FindGameObjectsWithTag ("Ball");
foreach (GameObject b in Balls) {
//Resizing
b.transform.localScale = new Vector3 (0.5f, 0.5f, 0f);
//Changing bounce value
b.GetComponent<CircleCollider2D> ().sharedMaterial.bounciness = 1f;
}
}
Here, as shown in the pictures:
I wanted to created a scene of balls getting created endlessly from above and then the ball's components are modified when they roll through the trigger near the final edge. So, I attached the above script to the trigger object.
The original values were: localScale of balls - - - (1,1,1) _ Friction & Bounciness of PhysicsMaterial2D inside CircleCollider2D - - - 0.4 & 0
The scale values reverts back to original after I played once and restarted. But, the bounciness stays the changed value 1, it doesn't go back to original at second time Playing and onwards. Balls are having Bounciness 1 before trigger! Please help !
I'm a beginner so if I made stupid mistakes, I'm very sorry...
Your answer
Follow this Question
Related Questions
i can not get a single physical material to work. 1 Answer
Changing Physic materials with a script. 0 Answers
How to get the value of the String Variable from another script? 0 Answers
Get() and Set() values of a gridArray from another scipt 0 Answers
I'm a newbie to scripting and I tried the roll a ball tutorial and got a error with my script 0 Answers