Does any one know how to change Update to something else for example: I have this code which lets my object move.... and i would like to change that code from (to make it stop) THIS transform.position += Vector3.up * Time.deltaTime*speed; TO THIS transform.position -= Vector3.up * Time.deltaTime*speed; On Collision. This is my code: Code (csharp): float speed = 5.0f; void Update() { transform.position += Vector3.up * Time.deltaTime*speed; } void OnCollisionEnter2D(Collision2D collision) { DestroyObject(collision.gameObject); transform.position -= Vector3.up * Time.deltaTime*speed; } public void SetSpeed(float modifier) { speed = 5.0f + modifier; } }
I would create a variable, like direction, which is either 1 or -1, in CollisionEnter2D I would set it to -1, then I'd multiply the whole Vector3.up * Time.deltaTime * speed thing with it
not sure if this is what you're after. but it might get you on the right path Code (CSharp): float speed = 5.0f; bool isFwd = true; void Update() { if(isFwd) { transform.position += Vector3.up * Time.deltaTime*speed; }else { transform.position -= Vector3.up * Time.deltaTime*speed; } } void OnCollisionEnter2D(Collision2D collision) { DestroyObject(collision.gameObject); isFwd = false; } public void SetSpeed(float modifier) { speed = 5.0f + modifier; } }