No. I am not downloading that just to read it.
Post your code on the forums in code tags, like everyone else. Then we will check it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DoorOpen : MonoBehaviour
{
public PlayerRay playerray;
public Vector3 AfterAngles;
public Animator animator;
public Vector3 CurrentAngles;
public GameObject Door;
public float x;
public float y;
public float z;
public float x1;
public float y1;
public float z1;
public bool DoorIsOpen = false;
public bool DoorIsClosed = true;
public bool PlayerIsNear = false;
public Text InfoText;
public GameObject TextParent;
// Start is called before the first frame update
public void Start()
{
TextParent.SetActive(false);
Door = this.gameObject;
animator = GetComponent<Animator>();
}
// Update is called once per frame
public void Update()
{
if (Input.GetKeyDown(KeyCode.E) && DoorIsOpen == false && PlayerIsNear == true)
{
animator.SetTrigger("OpenDoor");
x = CurrentAngles.x;
y = CurrentAngles.y;
z = CurrentAngles.z;
Door.GetComponent<Transform>().eulerAngles = CurrentAngles;
Door.GetComponent<Transform>().eulerAngles.Set(x, y -= 90, z);
Door.GetComponent<Transform>().eulerAngles = AfterAngles;
x1 = AfterAngles.x;
y1 = AfterAngles.y;
z1 = AfterAngles.z;
}
if (Input.GetKeyDown(KeyCode.E) && DoorIsOpen == true && PlayerIsNear == true)
{
animator.SetTrigger("CloseDoor");
x = CurrentAngles.x;
y = CurrentAngles.y;
z = CurrentAngles.z;
Door.GetComponent<Transform>().eulerAngles = CurrentAngles;
Door.GetComponent<Transform>().eulerAngles.Set(x, y += 90, z);
Door.GetComponent<Transform>().eulerAngles = AfterAngles;
x1 = AfterAngles.x;
y1 = AfterAngles.y;
z1 = AfterAngles.z;
}
if (playerray.IsOpen == true)
{
//Debug.Log("we hit" + hit.collider.name + " " + hit.point);
rayopen();
}
else
{
rayclose();
}
}
public void open()
{
DoorIsOpen = true;
DoorIsClosed = false;
}
public void close()
{
DoorIsOpen = false;
DoorIsClosed = true;
}
public void rayopen()
{
TextParent.SetActive(true);
PlayerIsNear = true;
Debug.Log("welcome");
InfoText.text = ("press E");
}
public void rayclose()
{
PlayerIsNear = false;
TextParent.SetActive(false);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerRay : MonoBehaviour
{
public bool IsOpen;
public GameObject DoorParent;
public DoorOpen dooropen;
public LayerMask door;
private Camera cam;
// Start is called before the first frame update
private void Start()
{
dooropen = DoorParent.GetComponentInChildren<DoorOpen>();
cam = Camera.main;
}
// Update is called once per frame
private void Update()
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 5, door))
{
Debug.Log("we hit" + hit.collider.name + " " + hit.point);
//dooropen.rayopen();
IsOpen = true;
}
else
{
//dooropen.rayclose();
IsOpen = false;
}
}
}
playerray
to a valid value within that class why would you expect it to not be null?Thanks i try thatConsidering that nothing setsplayerray
to a valid value within that class why would you expect it to not be null?
So you need to add code before line 61 which will check all the player rays within the world is nearest and then use that instance to initialize the variable.