- Home /
Sharing booleans between 2 scripts
Im having trouble linking one boolean to another. ive looked at many current anwsers but allways get stuck.
here is code:
 SCRIPT1
 using UnityEngine;
 using System.Collections;
 
 public class Manager : MonoBehaviour {
     
     public Transform Rock;
     public static Transform Storage;
     private Vector3 moveDirection = Vector3.zero;
     public float speed = 0.5F;
     
     public bool GoToStorage;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
         transform.LookAt(Rock);
         transform.Translate(Vector3.forward * speed);
         
     
         if(GoToStorage == true){
             
             
             
         transform.LookAt(Storage);
         transform.Translate(Vector3.forward * speed);
     
             
             
         }
 SCRIPT2
 
 using UnityEngine;
 using System.Collections;
 
 public class CollisionDetection : MonoBehaviour
 {
     public Transform Storage;
     public GameObject AI;
     private RaycastHit hit;
     
     public Manager a;
     // Use this for initialization
     void Start ()
     {
     
         
     
     }
     
     // Update is called once per frame
     void Update ()
     {
     
         
         Vector3 forward = transform.TransformDirection (Vector3.forward) * 10;
         
         Debug.DrawRay (transform.position, forward, Color.red);
         
         if (Physics.Raycast(transform.position, forward, out hit, 10))
 
             
             if (hit.collider.tag == "Rock"){
             
              Destroy(hit.transform.gameObject); // destroy the object hit
             
             //Set the storage variable to true
             
             
             
             if (hit.collider.tag == "Storage"){
             
              print ("Item Stored!");
             
             
             
             
             
             
             
         }
             
         }
         
             
             
             
             
     }
             
             
             
 }
 
     
               Comment
              
 
               
              I dont see you using "$$anonymous$$anager a" at all in script 2
Answer by Dave-Carlile · Jan 30, 2013 at 09:40 PM
Unity Gems has a good tutorial on script interaction.
Your answer
 
 
             Follow this Question
Related Questions
GetComponent with variable script possible? 1 Answer
Using a Variable over two Scripts 4 Answers
Boolean not switching? 2 Answers
Yield Waitforseconds not working at all 3 Answers
ANOTHER Boolean Problem 1 Answer
