Reputation: 11
I am making an object move continuously and the code for that is:
myRenderer = gameObject.GetComponent<SpriteRenderer>();
speed_target = Random.Range (15, 20);
rigidbody.velocity = transform.right * speed_target;
I have another gameobject which when clicked has to reduce the speed of this moving object.
Please tell me the code which has to be written in this Script in void OnMouseDown.
Upvotes: 0
Views: 991
Reputation: 11
Why can't you just use a speed modifier variable in your original speed equation that increases or decreases the target gameobject's speed? In the mouse down event, change the modifier as necessary.
Example: rigidbody.velocity = transform.right * speed_target * MODIFIER;
Upvotes: 1