- Home /
If cubes Collide controlls work if they dont collide they dont work
Hello i made an empty object that i set to the movement with my camera around the player so what i am trying to make is if(the cubes are colliding with this object){all staff here work only for the cubes that are collideing and if they go out of the collider they act normal } So i dont know why but when 1 cube collide with this object all began to do an activity that i set i want only the cubes that are in the collider to do something.Also the if's inside stop working ieven if they collide only E is working My code:
using UnityEngine; using System.Collections;
public class KeysInCollider : MonoBehaviour { public bool Gravitronned = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (Gravitronned == true) {
if (Input.GetKeyDown (KeyCode.C)) {
Physics.gravity *= 0;
}
if (Input.GetKeyDown (KeyCode.X)) {
Physics.gravity = new Vector3 (0, -3.0F, 0);
}
if (Input.GetKeyDown (KeyCode.V)) {
Physics.gravity = new Vector3 (0, 3.0F, 0);
}
if (Input.GetKeyDown (KeyCode.Q)) {
GetComponent<Rigidbody> ().velocity = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
}
if (Input.GetKeyUp (KeyCode.Q)) {
Physics.gravity = new Vector3 (0, -6.0F, 0);
}
if (Input.GetKeyDown (KeyCode.E)) {
GetComponent<Rigidbody> ().velocity = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
}
if (Input.GetKeyUp (KeyCode.E)) {
Physics.gravity *= 0;
}
if (Input.GetKeyDown (KeyCode.R)) {
GetComponent<Rigidbody>().isKinematic = true;
}
if (Input.GetKeyUp (KeyCode.R)) {
GetComponent<Rigidbody> ().isKinematic = false;
}
}
else
{
Physics.gravity = new Vector3 (0, -6.0F, 0);
}
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.name == "IfInScreenGrv") {
Gravitronned = true;
} else
{
Gravitronned = false;
}
}
}
Your answer
Follow this Question
Related Questions
I am having a problem with detecting certain collision? 1 Answer
differentiate between box collider of two different Game Objects in UNITY 1 Answer
object not colliding with another object,,.but getting merged and passing each other. 2 Answers
How to Change a Weapon with tag? 1 Answer
[error] Getting errors from Photon Networking when creating standalone! 0 Answers