Hi Im using FPS kit by Aiden Studio and I want to add simple thing. If I click on button, player name in GUI will be red. There is script what generate GUI with everything. Please help me!
using UnityEngine;
using System.Collections;
public class characterControls : MonoBehaviour {
public int health = 100;
public float speed = 10.0f;
public float gravity = 10.0f;
public float maxVelocityChange = 10.0f;
public bool canJump = true;
public float jumpHeight = 2.0f;
private bool grounded = false;
public SkinnedMeshRenderer[] skinnedPlayerMeshes;
public MeshRenderer[] playerMeshes;
public GameObject fpCam;
public float bloodyScreenDuration = 3;
public Texture[] bloodyScreens;
float bloodTimer = 0;
public PhotonView pv;
public GameObject ragdoll;
public GUISkin guiSkin;
mouseLook mL;
public bool isPaused = false;
void Awake()
{
GetComponent<Rigidbody>().freezeRotation = true;
GetComponent<Rigidbody>().useGravity = false;
if (pv.isMine)
{
pv.RPC("setName", PhotonTargets.AllBuffered, PhotonNetwork.playerName);
pv.RPC("updateWep", PhotonTargets.AllBuffered, PhotonNetwork.player.GetScore());
mL = fpCam.GetComponent<mouseLook>();
}
}
[PunRPC]
public void setName(string nm)
{
gameObject.name = nm;
}
void Update()
{
if (bloodTimer > 0)
{
bloodTimer -= Time.deltaTime;
}
}
void FixedUpdate()
{
if (grounded && pv.isMine)
{
// Calculate how fast we should be moving
Vector3 targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
// Apply a force that attempts to reach our target velocity
Vector3 velocity = GetComponent<Rigidbody>().velocity;
Vector3 velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
GetComponent<Rigidbody>().AddForce(velocityChange, ForceMode.VelocityChange);
if (health <= 0)
{
pv.RPC("Die", PhotonTargets.AllBuffered, null);
}
// Jump
if (canJump && Input.GetButton("Jump"))
{
GetComponent<Rigidbody>().velocity = new Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
}
isPaused = Input.GetKey(KeyCode.Tab);
mL.enabled = !isPaused;
if (isPaused)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
} else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
if (Input.GetKeyUp(KeyCode.F5))
{
pv.RPC("gotKill", PhotonTargets.AllBuffered, "loser");
}
}
// We apply gravity manually for more tuning control
GetComponent<Rigidbody>().AddForce(new Vector3(0, -gravity * GetComponent<Rigidbody>().mass, 0));
grounded = false;
}
void OnCollisionStay()
{
grounded = true;
}
float CalculateJumpVerticalSpeed()
{
// From the jump height and gravity we deduce the upwards speed
// for the character to reach at the apex.
return Mathf.Sqrt(2 * jumpHeight * gravity);
}
string killerWep = "World";
string killer = "Null";
[PunRPC]
public void ApplyDamage(int dmg, string wepName, string kilr)
{
if (kilr != gameObject.name)
{
health -= dmg;
killerWep = wepName;
killer = kilr;
if (pv.isMine)
{
blood = bloodyScreens[Random.Range(0, bloodyScreens.Length)];
bloodTimer = bloodyScreenDuration;
if (health <= 0)
{
pv.RPC("Die", PhotonTargets.AllBuffered, null);
}
}
}
}
Texture blood;
Vector2 scroll = Vector2.zero;
void OnGUI()
{
GUI.skin = guiSkin;
GUI.Box (new Rect (10, Screen.height - 100, 145, 30), "HP | " + health);
if (bloodTimer > 0) {
Color c = Color.white;
c.a = bloodTimer;
GUI.color = c;
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), blood, ScaleMode.StretchToFill);
}
if (isPaused) {
GUILayout.BeginArea (new Rect (Screen.width / 2 - 500, Screen.height / 2 - 200, 300, 500));
GUILayout.BeginVertical ("Box");
GUILayout.Label ("Paused");
scroll = GUILayout.BeginScrollView (scroll, "Window");
GUILayout.BeginHorizontal ();
GUILayout.Label ("Player ");
GUILayout.Label ("Kills");
GUILayout.Label (" Weapon");
GUILayout.EndHorizontal ();
foreach (PhotonPlayer pl in PhotonNetwork.playerList) {
GUILayout.BeginHorizontal ("Box");
GUILayout.Label (pl.NickName + " ");
GUILayout.Label (pl.GetScore () + " ");
GUILayout.EndHorizontal ();
}
GUILayout.EndScrollView ();
if (GUILayout.Button ("Suicide")) {
if (pv.isMine) {
pv.RPC ("ApplyDamage", PhotonTargets.AllBuffered, 10000, "Suicide", "Self");
}
}
if (GUILayout.Button ("Resume")) {
isPaused = false;
}
if (GUILayout.Button ("Disconnect")) {
PhotonNetwork.LeaveRoom ();
UnityEngine.SceneManagement.SceneManager.LoadScene (1);
}
GUILayout.EndVertical ();
GUILayout.EndArea ();
}
}
bool dead = false;
[PunRPC]
public void Die()
{
if (!dead)
{
dead = true;
Destroy(gameObject);
if (pv.isMine)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
PhotonNetwork.Instantiate(ragdoll.name, transform.position, transform.rotation, 0);
GameObject.Find("_Room").GetComponent<roomManager>().isSpawned = false;
GameObject.Find("_Room (2)").GetComponent<roomManager>().isSpawned = false;
GameObject.Find("_Network").GetComponent<PhotonView>().RPC("getKillFeed", PhotonTargets.All, PhotonNetwork.player.NickName, killer, killerWep);
if (GameObject.Find(killer) != null)
{
GameObject.Find(killer).GetComponent<PhotonView>().RPC("gotKill", PhotonTargets.AllBuffered, PhotonNetwork.playerName);
}
}
}
}
[PunRPC]
public void gotKill(string victim)
{
if (pv.isMine)
{
PhotonNetwork.player.AddScore(1);
pv.RPC("updateWep", PhotonTargets.AllBuffered, PhotonNetwork.player.GetScore());
}
Debug.Log("Killed " + victim + "! Score: " + PhotonNetwork.player.GetScore());
}
[PunRPC]
public void destroy()
{
Destroy(gameObject);
}
}