- Home /
Set bool to different objects with 1 script
Hello i readed all google pages and everything i could find but nothing helped me so i have to ask here: i made a script attached to 100 cubes it says
using UnityEngine;
using System.Collections;
public class IfClose : MonoBehaviour {
public bool Gravitronned= false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider col)
{
if (col.gameObject.name == "IfInScreenGrv") {
Gravitronned = true;
}
else
{
Gravitronned = false;
}
}
}
and then i have another script that says
using UnityEngine;
using System.Collections;
public class TimeFreeze : MonoBehaviour {
static bool GravitronedTwice;
// Use this for initialization
void Start () {
}
void Update ()
{
GravitronedTwice = gameObject.GetComponent<IfClose> ().Gravitronned;
if (GravitronedTwice = true) {
if (Input.GetKeyDown (KeyCode.V)) {
Physics.gravity = new Vector3 (0, 3.0F, 0);
}
}
}
}
so when i press V i want the cube only in this area to get Physics.gravity = new Vector3 (0, 3.0F, 0); [1]: /storage/temp/47667-yesssssssssssssss.png others stay ass they are ![alt text][1]
Answer by Jinxology · Jun 05, 2015 at 06:53 PM
Change:
if (GravitronedTwice = true) {
to
if (GravitronedTwice == true) {
Get rid of the static keyword, you dont want that. That makes that variable shared across every instance.
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Colliders going through Colliders? 1 Answer
Wheel colliders not detecting mesh colliders 1 Answer
Stop buildings from spawning inside eachother 1 Answer
Cannot detect edge collider 1 Answer