- Home /
How to turn on and turn off function with button.
Hello guys :) pretty easy question,but not so easy to me :D So i have made Cube "sticky" i mean it sticks to every collision that it touches.Well i want to make this a bit different,i want it only stick when i press "f" button and when it is stuck on collision,i walk a bit closer to that cube and press again "f" button then cube is no longer sticky.I hope you understand me,please if you have any questions just ask me,and please help me :o
Here is the script:
using UnityEngine;
using System.Collections;
public class StickyObject : MonoBehaviour {
void OnCollisionEnter(Collision c) {
var joint = gameObject.AddComponent<FixedJoint>();
joint.connectedBody = c.rigidbody;
}
}
and javascript too:
function OnCollisionEnter(c : Collision) {
var joint = gameObject.AddComponent(FixedJoint);
joint.connectedBody = c.rigidbody;
}
Answer by Piflik · Dec 29, 2012 at 01:13 PM
Use a boolean variable, and set it to true/false when you press the button. Then use this variable to control your function with an if statement.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
function Start () problem!! 3 Answers
On var enter 1 Answer
Have null errors 1 Answer
Player Controller Rotation Script Help 2 Answers