Don't wanna be here? Send us removal request.
Text
AI Patrol Script
using UnityEngine; using System.Collections;
public class AIPatrol : MonoBehaviour {
public float speed; private float parameter; public GameObject[] nodes;
private NavMeshAgent agent;
public Vector3 AiTargetPos; private int i;
private Animator anim;
void Awake() { nodes = GameObject.FindGameObjectsWithTag("Node"); } //Gets the navmesh agent component and animator component void Start () {
agent = GetComponent<NavMeshAgent>();
anim = this.gameObject.GetComponent<Animator>();
//Creates a random range from the nodes set in scene i = Random.Range(0, nodes.Length); AiTargetPos = nodes[i].transform.position; }
void Update() { //create a distance check between AI and target parameter = Vector3.Distance(transform.position, AiTargetPos);
Patrol(parameter);
} void Patrol (float dist) { //Set the animator to ensure walking animation anim.SetFloat("Forward", agent.speed*.15f, 0.1f, Time.deltaTime);
//Sets a new destination if AI gets close to destination if (dist > 2f) { agent.SetDestination(AiTargetPos); }
//continues on path else if (dist <= 2f) { int i = Random.Range(0, nodes.Length); AiTargetPos = nodes[i].transform.position; } } }
0 notes
Text
Player Stats Script
using UnityEngine; using UnityEngine.SceneManagement; using System.Collections;
public class PlayerStats : MonoBehaviour {
private Transform spawnPoint; public Transform currentCheckPoint;
// Respawns player if hit respawn object at checkpoint void OnCollisionEnter(Collision col) {
if (col.gameObject.CompareTag("Respawn")) { Debug.Log("Landed on respawn"); transform.position = currentCheckPoint.position; }
} }
0 notes
Text
Player HandController Script
using UnityEngine; using System.Collections;
public class HandController : MonoBehaviour { public Transform handRightGO; public Transform handLeftGO;
private Animator anim;
public bool ikActive = false;
public void Start() { anim = this.gameObject.GetComponent<Animator>(); }
//uses inverse kinematics to change hand position when player holding object public void OnAnimatorIK() { if(anim) { if(ikActive) { anim.SetIKPositionWeight(AvatarIKGoal.RightHand, 1); anim.SetIKPosition(AvatarIKGoal.RightHand, handRightGO.position);
anim.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1); anim.SetIKPosition(AvatarIKGoal.LeftHand, handLeftGO.position);
anim.SetIKRotationWeight(AvatarIKGoal.RightHand, 1); anim.SetIKRotation(AvatarIKGoal.RightHand, handRightGO.rotation);
anim.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1); anim.SetIKRotation(AvatarIKGoal.LeftHand, handLeftGO.rotation); } else { anim.SetIKPositionWeight(AvatarIKGoal.RightHand, 0); anim.SetIKRotationWeight(AvatarIKGoal.RightHand, 0); } } } }
0 notes
Text
Platform Drop Script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlatformDrop : MonoBehaviour {
public Rigidbody rb;
// Use this for initialization void Start () {
rb = GetComponent<Rigidbody>(); }
void OnCollisionEnter(Collision col) { //turns on the rigidbody gravity if player makes contact if (col.gameObject.name == "Player") { Debug.Log("Player made contact"); rb.useGravity = true; }
//deactivates gameobject if hits the respawn object if (col.gameObject.tag == "Respawn") { gameObject.SetActive(false); } } // Update is called once per frame void Update () { } }
0 notes
Text
Open Wall with Key
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class OpenWithKey : MonoBehaviour {
private CollectItem collectItem;
void Start () {
collectItem = GameObject.Find("Key").GetComponent<CollectItem>(); }
//Opens door object if player within trigger and has collected item void OnTriggerStay (Collider other) { if (collectItem.ItemCollected == true && Input.GetKeyDown(KeyCode.E)) { Debug.Log("Door Open"); gameObject.SetActive(false); } } }
0 notes
Text
CheckPoint Script
using UnityEngine; using System.Collections;
public class CheckPoint : MonoBehaviour {
public PlayerStats PS;
// Use this for initialization void Start () { } // Update is called once per frame void OnTriggerEnter (Collider other) { //checks tag if player and sets the checkpoint as this checkpoint position if (other.CompareTag("Player")) { Debug.Log("Player Collided"); PS.currentCheckPoint = transform; } } }
0 notes
Text
MenuController Script
using UnityEngine; using UnityEngine.SceneManagement; using System.Collections;
public class MenuController : MonoBehaviour {
//Methods that link with the buttons on the main menu
public void startButton() { SceneManager.LoadScene("Juan-Reloaded-Hub"); }
public void quitGame() { Application.Quit(); }
public void Controls() { SceneManager.LoadScene("ControlScreen"); }
}
0 notes
Text
GameManager Script
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class GameManager : MonoBehaviour {
//Creates instance and ensures that a gamemanager is present static private GameManager _instance = null; static public GameManager _Instance { get { if ( _instance == null ) { _instance = FindObjectOfType<GameManager>();
if ( _instance == null ) Debug.LogError ( "No Game Manager Found!!" ); }
return _instance; } }
//variable to track amount of walls fixed [HideInInspector] public int WallsFixed;
public Text Counter = null; public GameObject PausePanel; private bool PauseActive = false;
//make sure only one buildmanager void Awake() { if ( _instance != null && _instance != this ) Destroy ( this );
_instance = this; }
//method that increments the walls fixed UI counter public void ChangeCounter ( int value ) { WallsFixed += value;
Counter.text = "Walls Fixed: " + WallsFixed.ToString(); }
public void Update() { PauseGame(); }
//Pauses game public void PauseGame() { if (Input.GetKeyDown(KeyCode.Escape)) { if (PauseActive) { PausePanel.SetActive(false); Time.timeScale = 1; PauseActive = false; } else { Time.timeScale = 0; PausePanel.SetActive(true); PauseActive = true; } } }
//Resumes game on button click public void Resume() { Time.timeScale = 1; PausePanel.SetActive(false); } }
0 notes
Text
BuildWall script
using System.Collections; using System.Collections.Generic; using UnityEngine;
[RequireComponent(typeof(AudioSource))] public class Open : MonoBehaviour {
public Mesh Wall1; public Mesh Wall2;
private MeshFilter meshFilter;
private GameObject arrow;
public AudioSource audio;
public AudioClip buildSound;
// Use this for initialization void Start () {
meshFilter = GetComponent<MeshFilter>();
if (meshFilter.mesh == null) meshFilter.mesh = Wall1;
arrow = this.gameObject.transform.GetChild(0).gameObject;
AudioSource audio = GetComponent<AudioSource>(); }
//changes meshfilter on trigger collision void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Rock") { meshFilter.mesh = Wall2; other.gameObject.SetActive(false); GameObject.Find("ThirdPersonController").GetComponent<HandController>().ikActive = false;
//increments walls fixed counter GameManager._Instance.ChangeCounter ( 1 ); //Plays audio audio.PlayOneShot(buildSound);
arrow.SetActive(false);
} } }
0 notes
Text
Object PickUp Script
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PickUp : MonoBehaviour {
//bool InTrigger = false;
bool HasPickedUp = false; private float disToPlayer; private GameObject playerObj;
public GameObject RockHelp; public GameObject PortalText;
public GameObject NextLvlPortal;
// Use this for initialization void Start () {
playerObj = GameObject.FindWithTag("Player");
} // Update is called once per frame void Update () {
Rigidbody rbody = GetComponent<Rigidbody>();
//distance check between player and rock disToPlayer = Vector3.Distance(transform.position, playerObj.transform.position);
//opens portal to next level if (GameManager._Instance.WallsFixed == 6) { NextLvlPortal.SetActive(true); PortalText.SetActive(true); }
//Tells hint to player if within range if (disToPlayer < 5f && !HasPickedUp) { RockHelp.SetActive(true); }
else if (disToPlayer > 5f) { RockHelp.SetActive(false); }
//picks up object and sets in empty slot if it has not already been picked up if (disToPlayer < 2f && Input.GetKeyDown(KeyCode.E)) { if (HasPickedUp) { transform.parent = null; rbody.isKinematic = false;
gameObject.layer = 0; gameObject.layer = LayerMask.NameToLayer("Default");
HasPickedUp = false;
GameObject.Find("ThirdPersonController").GetComponent<HandController>().ikActive = false; } else { transform.parent = playerObj.transform; transform.position = playerObj.transform.FindChild("GameObject").position; rbody.isKinematic = true; Debug.Log("Object Picked Up");
GameObject.Find("ThirdPersonController").GetComponent<HandController>().ikActive = true;
gameObject.layer = 0; gameObject.layer = LayerMask.NameToLayer("Pickup");
HasPickedUp = true; } } } }
0 notes