I am making a game where you can build bases/armies, and destroy your enemies base/army.
My Problem is that my building controller has a variable for the player controller. When I place a new building the variable for the player controller becomes null. Is there any way I can automatically attach my player controller?
Here is my curent building controller script:
using UnityEngine;
using System.Collections;
using UnityEngine;
using System.Collections;
public class BUILDINGCONTROLS: MonoBehaviour {
public playercontrols PLAYERPORT; //PLAYER CONTROLS SCRIPT
public Transform MYWAYPOINT; //For Unit Training
public Texture HIGHLIGHT; //Texture for when the mouse is over the building
public Texture NORM; //Normal Texture
void OnMouseOver ()
{
renderer.material.mainTexture = HIGHLIGHT;
if (Input.GetMouseButtonDown (0)) {
//Send info to the player
PLAYERPORT.selected_unit = transform.tag;
PLAYERPORT.selected_unit_transform = MYWAYPOINT.transform;
PLAYERPORT.selected_unit_type = "Building";
PLAYERPORT.selected_object = gameObject;
}
}
void OnMouseExit(){
renderer.material.mainTexture = NORM;
}
}