Im new to unity and scripting and managed to make a script for clicking on an object to mute/unmute it, but only at a close range. The problem I have now is Im trying to seperate them so that one script checks the distance, another mutes/unmutes, and another to change the GUI crosshair colour. I should tell you in advance I only started to learn scripting of any kind yesterday.
This is the script to check distance:
using UnityEngine;
using System.Collections;
public class muteaudioclick : MonoBehaviour
{
public int triggdist = 3;
public Transform player;
private int distance;
public bool playerclose;
void Onupdate(){
float distance = Vector3.Distance(player.position, transform.position);
if(distance < triggdist)
{
playerclose = true;
}
else
{
playerclose = false;
}
}
}
This is for muting
using UnityEngine;
using System.Collections;
public class muteaudioclick : MonoBehaviour
{
private checkplayerdist playerclose;
void Awake()
{
playerclose = GetComponent<checkplayerdist>();
}
void OnMouseDown()
{
if(playerclose == true)
{
if(audio.mute == false)
{
audio.mute = true;
Debug.Log ("Sound Off");
}
else
{
audio.mute = false;
Debug.Log ("Sound On");
}
}
}
}
And finally the crosshair, I havent even tried to incorperate this yet, trying to get the mute function to work.
using UnityEngine;
using System.Collections;
public class CrosshairGUI : MonoBehaviour
{
void OnGUI()
{
GUI.color = Color.white;
GUI.Label (new Rect(Screen.width/2,Screen.height/2, 50, 50), "X");
}
}