- Home /
Collision problem
I made a game where the player goes through the platform when it changes color, but he did not return to normal when he leaves the platform, how can she return to normal when the player get through it? here my script:
using UnityEngine; using System.Collections;
public class Colortest : MonoBehaviour { public bool color = false;
// Use this for initialization void Start() { }
// Update is called once per frame
void Update()
{
if (color == true)
{
renderer.material.color = Color.blue;
}
}
void OnCollisionEnter2D (Collision2D col)
{
if (col.gameObject.tag == "Player")
{
color = true;
}
}
}
Comment
1) please format ALL of your code.
2) if you want to do something when an object leaves a collision box, use OnTriggerExit
- check the docs.
Your answer
Follow this Question
Related Questions
Player not colliding 0 Answers
Help With Colliders 3 Answers
Collision.impulse.Set doesn't change the impulse's values 0 Answers
OnDestroy collision detect 4 Answers