Hi! I want to get target form CameraControl.cs to Player.cs here is my script
CameraControl.cs
using UnityEngine;
using System.Collections;
public class CameraControl : MonoBehaviour {
RaycastHit hit;
bool leftClickFlag = true;
public GameObject actor;
public string floorTag;
public Vector3 target;
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Mouse0) && leftClickFlag)
leftClickFlag = false;
if (!Input.GetKey(KeyCode.Mouse0) && !leftClickFlag)
{
leftClickFlag = true;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 1500))
{
if (hit.transform.tag == floorTag)
{
float X = hit.point.x;
float Z = hit.point.z;
target = new Vector3(X, actor.transform.position.y, Z);
}
}
}
}
}
Player.cs
using UnityEngine;
using System.Collections;
public class Player : Character {
public Vector3 Pos;
private CameraControl CameraControlSc;
/* ============================== CONTROLS ============================== */
void Awake ()
{
CameraControlSc = GetComponent<CameraControl>();
}
public void Update () {
isLeft = false;
isRight = false;
isUp = false;
isDown = false;
print ("Target is"+CameraControlSc.target);
UpdateMovement();
}
/* ============================== TRIGGER EVENTS ====================================================================== */
void OnTriggerEnter(Collider other)
{
// did the player collide with a pickup?
// pickups and scoring will be added in an upcomming tutorial
if (other.gameObject.CompareTag("Pickup"))
{
if (other.GetComponent<Pickup>())
{
other.GetComponent<Pickup>().PickMeUp();
xa.sc.Pickup(); // tell Scoring.cs that we collected a pickup
}
}
}
}
After run console say
NullReferenceException: Object reference not set to an instance of an object
Player.Update () (at Assets/Scripts/Player.cs:23)
Please tell me what Did I Do Wrong, thank you