Hi to all I have some problems with two scripts I’m trying to merge togheter to make my raycast door script to work
this is the script for the crossahir gui
using UnityEngine;
using System.Collections;
public class CrosshairGUI : MonoBehaviour {
public Texture2D m_crosshairTexture;
public Texture2D m_useTexture;
public float RayLength = 3f;
public bool m_DefaultReticle;
public bool m_UseReticle;
public bool m_ShowCursor = false;
private bool m_bIsCrosshairVisible = true;
private Rect m_crosshairRect;
private Ray playerAim;
private Camera playerCam;
void Update (){
playerCam = Camera.main;
Ray playerAim = playerCam.GetComponent<Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
RaycastHit hit;
if (Physics.Raycast (playerAim, out hit, RayLength))
{
if(hit.collider.gameObject.tag == "Interact")
{
m_DefaultReticle = false;
m_UseReticle = true;
}
if(hit.collider.gameObject.tag == "InteractItem")
{
m_DefaultReticle = false;
m_UseReticle = true;
}
if(hit.collider.gameObject.tag == "Door")
{
m_DefaultReticle = false;
m_UseReticle = true;
}
}else{
m_DefaultReticle = true;
m_UseReticle = false;
}
/*
if(!m_ShowCursor){
Cursor.visible = (false);
Cursor.lockState = CursorLockMode.Locked;
}else{
Cursor.visible = (true);
Cursor.lockState = CursorLockMode.None;
}
*/
if(Input.GetKeyDown(KeyCode.C)) {
m_ShowCursor = !m_ShowCursor;
}
if(m_ShowCursor){
Cursor.visible = (true);
Cursor.lockState = CursorLockMode.None;
}
else {
Cursor.visible = (false);
Cursor.lockState = CursorLockMode.Locked;
}
}
void Awake (){
if(m_DefaultReticle){
m_crosshairRect = new Rect((Screen.width - m_crosshairTexture.width) / 2,
(Screen.height - m_crosshairTexture.height) / 2,
m_crosshairTexture.width,
m_crosshairTexture.height);
}
if(m_UseReticle){
m_crosshairRect = new Rect((Screen.width - m_useTexture.width) / 2,
(Screen.height - m_useTexture.height) / 2,
m_useTexture.width,
m_useTexture.height);
}
}
void OnGUI (){
if(m_bIsCrosshairVisible)
if(m_DefaultReticle){
GUI.DrawTexture(m_crosshairRect, m_crosshairTexture);
}
if(m_UseReticle){
GUI.DrawTexture(m_crosshairRect, m_useTexture);
}
}
}
ant this is the script for door opening
########### Script for Opening Door && Use Reticle ###########
*/
#pragma strict
public class DoorOpening extends MonoBehaviour {
private var guiShow : boolean = false;
var isOpen : boolean = false;
var rayLength = 4;
/* DOOR SOUNDS in CLASS */
class DoorSoundsClass {
var PlayDoorSound : boolean;
var DoorObject : GameObject;
var DoorOpenSound : AudioClip;
var DoorCloseSound : AudioClip;
}
var DoorSounds : DoorSoundsClass = new DoorSoundsClass ( ) ;
/* MAIN FUNCTION */
function Update()
{
var Reticle : GUICrosshair = this.GetComponent(GUICrosshair);
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Door")
{
guiShow = true;
if(Input.GetKeyDown("e") && isOpen == false)
{
hit.collider.gameObject.animation.Play("DoorOpen");
if(DoorSounds.PlayDoorSound){
DoorSounds.DoorObject.audio.clip = DoorSounds.DoorOpenSound;
DoorSounds.DoorObject.audio.Play();
}
isOpen = true;
guiShow = false;
}
else if(Input.GetKeyDown("e") && isOpen == true)
{
hit.collider.gameObject.animation.Play("DoorClose");
if(DoorSounds.PlayDoorSound){
DoorSounds.DoorObject.audio.clip = DoorSounds.DoorCloseSound;
DoorSounds.DoorObject.audio.Play();
}
isOpen = false;
guiShow = false;
}
}
}
else
{
guiShow = false;
}
/* MAIN RETICLE USES */
if(guiShow == true && isOpen == false)
{
Reticle.m_UseReticle = true;
Reticle.m_DefaultReticle = false;
}
if(guiShow == false && isOpen == true)
{
Reticle.m_UseReticle = false;
Reticle.m_DefaultReticle = true;
}
if(guiShow == true && isOpen == true)
{
Reticle.m_UseReticle = true;
Reticle.m_DefaultReticle = false;
}
if(guiShow == false && isOpen == false)
{
Reticle.m_UseReticle = false;
Reticle.m_DefaultReticle = true;
}
}
}
i noticed that when i Import the dooropennig.js script console give me and error on line 24 about GUICrosshair…
can someone please help me??
many thanks in advance
Leon