├── TransparencyScript.js ├── SlowDownTime.cs ├── Bullet.cs ├── ChangeCheckpoint.cs ├── .gitignore ├── DestroyAfterTime.cs ├── DestroyOnTrigger.cs ├── ObjectsToCollect.cs ├── ComboHit.cs ├── CanonTriggerShoot.cs ├── Currency.cs ├── PlaySound.cs ├── Inventory.cs ├── PickupMoney.cs ├── PlayVideo.cs ├── Gun.cs ├── Checkpoint.cs ├── Teleport.cs ├── TurnLight.cs ├── ShowGUI.cs ├── Jumpscare.cs ├── Radiation.cs ├── CanonShoot.cs ├── ShowUI.cs ├── QuestMarker.cs ├── CountObjects.cs ├── UnlockAbility.cs ├── Territory.cs ├── OnTriggerLoadLevelV2.cs ├── UseInventory.cs ├── ShowQuest2.cs ├── DishonoredSpell.cs ├── Vendor.cs ├── Waypoints.cs ├── Quest.cs ├── ShowQuest.cs ├── ShowWeapon.cs ├── PickUp.cs ├── EnterVehicle.cs ├── ShootAuto.cs ├── ThrowObject.cs └── ThirdPersonCharacter.cs /TransparencyScript.js: -------------------------------------------------------------------------------- 1 | var alphaStart : float = 0.0; 2 | var alphaEnd : float = 1.0; 3 | var duration : float = 1.0; 4 | 5 | function Update() { 6 | 7 | var lerp : float = Mathf.PingPong(Time.time,duration)/duration; 8 | GetComponent.().material.color.a = Mathf.Lerp(alphaStart,alphaEnd,lerp); 9 | 10 | } -------------------------------------------------------------------------------- /SlowDownTime.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class SlowDownTime : MonoBehaviour { 5 | 6 | // Use this for initialization 7 | void Update () { 8 | if (Input.GetKey(KeyCode.Q)) 9 | { 10 | Time.timeScale = 0.65f; 11 | } 12 | else 13 | Time.timeScale = 1; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Bullet.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Bullet : MonoBehaviour { 6 | 7 | // Use this for initialization 8 | void Start () { 9 | Destroy(gameObject, 5); 10 | } 11 | 12 | // Update is called once per frame 13 | void OnCollisionEnter () { 14 | Destroy(gameObject); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ChangeCheckpoint.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ChangeCheckpoint : MonoBehaviour 6 | { 7 | public GameObject checkpoint; 8 | // Use this for initialization 9 | void OnTriggerEnter(Collider plyr) 10 | { 11 | if (plyr.gameObject.tag == "Player") 12 | Destroy(checkpoint); 13 | Destroy(gameObject); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD solution and project files 9 | ExportedObj/ 10 | *.csproj 11 | *.unityproj 12 | *.sln 13 | *.suo 14 | *.tmp 15 | *.user 16 | *.userprefs 17 | *.pidb 18 | *.booproj 19 | *.svd 20 | 21 | 22 | # Unity3D generated meta files 23 | *.pidb.meta 24 | 25 | # Unity3D Generated File On Crash Reports 26 | sysinfo.txt 27 | -------------------------------------------------------------------------------- /DestroyAfterTime.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class DestroyAfterTime : MonoBehaviour 5 | { 6 | public GameObject effect; 7 | public float Time; 8 | 9 | // Use this for initialization 10 | void Start() 11 | { 12 | Invoke("Explode", 5); 13 | } 14 | void Explode() 15 | { 16 | Instantiate(effect, gameObject.transform.position, gameObject.transform.rotation); 17 | Destroy(gameObject); 18 | } 19 | } -------------------------------------------------------------------------------- /DestroyOnTrigger.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class DestroyOnTrigger : MonoBehaviour 5 | { 6 | public GameObject objToDestroy; 7 | public GameObject effect; 8 | 9 | // Use this for initialization 10 | void OnTriggerEnter(Collider other) 11 | { 12 | if(other.gameObject.tag == "Player") 13 | Instantiate(effect, objToDestroy.transform.position, objToDestroy.transform.rotation); 14 | Destroy(objToDestroy); 15 | } 16 | } -------------------------------------------------------------------------------- /ObjectsToCollect.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ObjectsToCollect : MonoBehaviour { 6 | public static int objects = 0; 7 | // Use this for initialization 8 | void Awake () { 9 | objects++; 10 | } 11 | 12 | // Update is called once per frame 13 | void OnTriggerEnter(Collider plyr) 14 | { 15 | if (plyr.gameObject.tag == "Player") 16 | objects--; 17 | gameObject.SetActive(false); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ComboHit.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ComboHit : MonoBehaviour 6 | { 7 | Animator mAnim; 8 | 9 | void Start() 10 | { 11 | mAnim = GameObject.FindWithTag("Player").GetComponent(); 12 | } 13 | 14 | // Update is called once per frame 15 | void Update() 16 | { 17 | if (Input.GetButtonDown("Fire1")) 18 | { 19 | mAnim.SetTrigger("punch"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /CanonTriggerShoot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class CanonTriggerShoot : MonoBehaviour 5 | { 6 | 7 | public Transform posCanonball; 8 | public Rigidbody Canonball; 9 | float forceAmount = 13000; 10 | 11 | void OnTriggerEnter() 12 | { 13 | Rigidbody Canonrigidbody; 14 | Canonrigidbody = Instantiate(Canonball, posCanonball.position, posCanonball.rotation) as Rigidbody; 15 | Canonrigidbody.AddForce(posCanonball.forward * forceAmount); 16 | } 17 | } -------------------------------------------------------------------------------- /Currency.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class Currency : MonoBehaviour 7 | { 8 | 9 | public int gold; 10 | GameObject currencyUI; 11 | 12 | void Start() 13 | { 14 | currencyUI = GameObject.Find("Currency"); 15 | } 16 | void Update() 17 | { 18 | currencyUI.GetComponent().text = gold.ToString(); 19 | if (gold < 0) 20 | { 21 | gold = 0; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /PlaySound.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class PlaySound : MonoBehaviour { 5 | 6 | public AudioClip SoundToPlay; 7 | public float Volume; 8 | AudioSource audio; 9 | public bool alreadyPlayed = false; 10 | void Start() 11 | { 12 | audio = GetComponent(); 13 | } 14 | 15 | void OnTriggerEnter() 16 | { 17 | if (!alreadyPlayed) 18 | { 19 | audio.PlayOneShot(SoundToPlay, Volume); 20 | alreadyPlayed = true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Inventory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Inventory : MonoBehaviour { 6 | 7 | public GameObject invTab; 8 | 9 | // Use this for initialization 10 | void Start () { 11 | invTab.SetActive(false); 12 | } 13 | 14 | // Update is called once per frame 15 | void Update () { 16 | 17 | if (Input.GetKey(KeyCode.Tab)) 18 | { 19 | invTab.SetActive(true); 20 | } 21 | else 22 | { 23 | invTab.SetActive(false); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /PickupMoney.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PickupMoney : MonoBehaviour { 6 | 7 | Currency script; 8 | 9 | public int addAmount; 10 | 11 | void Start() 12 | { 13 | script = GameObject.FindWithTag("GameController").GetComponent(); 14 | } 15 | 16 | void OnTriggerEnter(Collider obj) 17 | { 18 | if (obj.gameObject.tag == "Player") 19 | { 20 | script.gold += addAmount; 21 | Destroy(gameObject); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /PlayVideo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PlayVideo : MonoBehaviour { 6 | 7 | public GameObject videoPlayer; 8 | public int timeToStop; 9 | 10 | // Use this for initialization 11 | void Start () { 12 | videoPlayer.SetActive(false); 13 | } 14 | 15 | // Update is called once per frame 16 | void OnTriggerEnter (Collider player) { 17 | 18 | if (player.gameObject.tag == "Player") 19 | { 20 | videoPlayer.SetActive(true); 21 | Destroy(videoPlayer, timeToStop); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Gun.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Gun : MonoBehaviour { 6 | 7 | public Transform bulletSpawn; 8 | public Rigidbody bullet; 9 | public float bulletSpeed; 10 | 11 | // Update is called once per frame 12 | void Update () { 13 | if (Input.GetButtonDown("Fire1")) 14 | { 15 | Rigidbody bulletRigidbody; 16 | bulletRigidbody = Instantiate(bullet, bulletSpawn.position, bulletSpawn.rotation) as Rigidbody; 17 | bulletRigidbody.AddForce(bulletSpawn.forward * bulletSpeed); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Checkpoint.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Checkpoint : MonoBehaviour { 6 | public Transform checkpoint; 7 | GameObject player; 8 | // Use this for initialization 9 | void Start () { 10 | 11 | player = GameObject.FindWithTag("Player"); 12 | } 13 | 14 | // Update is called once per frame 15 | void OnTriggerEnter (Collider plyr) { 16 | if(plyr.gameObject.tag == "Player") 17 | { 18 | player.transform.position = checkpoint.position; 19 | player.transform.rotation = checkpoint.rotation; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Teleport.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Teleport : MonoBehaviour 5 | { 6 | public GameObject ui; 7 | public GameObject objToTP; 8 | public Transform tpLoc; 9 | void Start() 10 | { 11 | ui.SetActive(false); 12 | } 13 | 14 | void OnTriggerStay(Collider other) 15 | { 16 | ui.SetActive(true); 17 | if ((other.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.E)) 18 | { 19 | objToTP.transform.position = tpLoc.transform.position; 20 | } 21 | } 22 | void OnTriggerExit() 23 | { 24 | ui.SetActive(false); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TurnLight.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class TurnLight : MonoBehaviour { 6 | 7 | public GameObject light; 8 | private bool on = false; 9 | 10 | // Use this for initialization 11 | void OnTriggerStay(Collider plyr) { 12 | if (plyr.tag == "Player" && Input.GetKeyDown(KeyCode.E) && !on) 13 | { 14 | light.SetActive(true); 15 | on = true; 16 | } 17 | else if (plyr.tag == "Player" && Input.GetKeyDown(KeyCode.E) && on) 18 | { 19 | light.SetActive(false); 20 | on = false; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /ShowGUI.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ShowGUI : MonoBehaviour { 5 | private bool showGUI = false; 6 | public Texture pressE; 7 | 8 | void OnTriggerEnter(Collider other) 9 | { 10 | if(other.gameObject.tag == "Player") 11 | showGUI = true; 12 | } 13 | void OnTriggerExit(Collider other) 14 | { 15 | if (other.gameObject.tag == "Player") 16 | showGUI = false; 17 | } 18 | 19 | 20 | void OnGUI() 21 | { 22 | if (showGUI == true) 23 | GUI.DrawTexture(new Rect(Screen.width / 1.5f, Screen.height / 1.4f, 178, 178), pressE); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Jumpscare.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Jumpscare : MonoBehaviour { 6 | 7 | public GameObject jumpscareObject; 8 | 9 | void Start () { 10 | 11 | jumpscareObject.SetActive(false); 12 | } 13 | 14 | void OnTriggerEnter (Collider player) { 15 | if(player.tag == "Player") 16 | { 17 | jumpscareObject.SetActive(true); 18 | StartCoroutine(DestroyObject()); 19 | } 20 | } 21 | IEnumerator DestroyObject() 22 | { 23 | yield return new WaitForSeconds(1.5f); 24 | Destroy(jumpscareObject); 25 | Destroy(gameObject); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Radiation.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Radiation : MonoBehaviour 5 | { 6 | public GameObject radiationEffect; 7 | // Use this for initialization 8 | void Start() 9 | { 10 | 11 | } 12 | 13 | // Update is called once per frame 14 | void OnTriggerEnter(Collider other) 15 | { 16 | if (other.gameObject.tag == "Player") 17 | { 18 | radiationEffect.SetActive(true); 19 | } 20 | } 21 | void OnTriggerExit(Collider other) 22 | { 23 | if (other.gameObject.tag == "Player") 24 | { 25 | radiationEffect.SetActive(false); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CanonShoot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class CanonShoot : MonoBehaviour 5 | { 6 | public Transform ballPos; 7 | public Rigidbody Ball; 8 | float forceAmount = 13000; 9 | public GameObject effect; 10 | 11 | void OnTriggerStay(Collider other) 12 | { 13 | Rigidbody ballRigid; 14 | if ((other.gameObject.tag == "Player") && Input.GetButtonDown("Use")) 15 | { 16 | ballRigid = Instantiate(Ball, ballPos.position, ballPos.rotation) as Rigidbody; 17 | ballRigid.AddForce(ballPos.forward * forceAmount); 18 | Instantiate(effect, ballPos.position, ballPos.rotation); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /ShowUI.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ShowUI : MonoBehaviour { 6 | 7 | public GameObject uiObject; 8 | void Start() 9 | { 10 | uiObject.SetActive(false); 11 | } 12 | // Update is called once per frame 13 | void OnTriggerEnter (Collider player) 14 | { 15 | if (player.gameObject.tag == "Player") 16 | { 17 | uiObject.SetActive(true); 18 | StartCoroutine("WaitForSec"); 19 | } 20 | } 21 | IEnumerator WaitForSec() 22 | { 23 | yield return new WaitForSeconds(5); 24 | Destroy(uiObject); 25 | Destroy(gameObject); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /QuestMarker.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class QuestMarker : MonoBehaviour { 6 | private GameObject player; 7 | private Vector3 playerPoint; 8 | private Quaternion objRot; 9 | // Use this for initialization 10 | void Start () { 11 | player = GameObject.FindWithTag("MainCamera"); 12 | } 13 | 14 | // Update is called once per frame 15 | void Update () { 16 | 17 | playerPoint = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z) - transform.position; 18 | objRot = Quaternion.LookRotation(-playerPoint, Vector3.up); 19 | transform.rotation = Quaternion.Slerp(transform.rotation, objRot, Time.deltaTime * 5); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /CountObjects.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class CountObjects : MonoBehaviour { 7 | public string nextLevel; 8 | public GameObject objToDestroy; 9 | GameObject objUI; 10 | // Use this for initialization 11 | void Start() 12 | { 13 | objUI = GameObject.Find("ObjectNum"); 14 | } 15 | // Update is called once per frame 16 | void Update () { 17 | objUI.GetComponent().text = ObjectsToCollect.objects.ToString(); 18 | if (ObjectsToCollect.objects == 0) 19 | { 20 | Application.LoadLevel(nextLevel); 21 | //Destroy(objToDestroy); 22 | objUI.GetComponent().text = "All objects collected."; 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /UnlockAbility.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class UnlockAbility : MonoBehaviour 6 | { 7 | public bool dishonoredSpell; 8 | public bool slowDownTime; 9 | // Use this for initialization 10 | void OnTriggerEnter(Collider col) 11 | { 12 | if (col.tag == "Player") 13 | { 14 | if (dishonoredSpell) 15 | { 16 | GameObject.FindWithTag("Player").GetComponent().enabled = true; 17 | Destroy(gameObject); 18 | } 19 | if (slowDownTime) 20 | { 21 | GameObject.FindWithTag("Player").GetComponent().enabled = true; 22 | Destroy(gameObject); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Territory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class Territory : MonoBehaviour { 7 | 8 | public string territoryName; 9 | public GameObject territoryUI; 10 | 11 | // Use this for initialization 12 | void Start () { 13 | 14 | territoryUI.SetActive(false); 15 | } 16 | 17 | // Update is called once per frame 18 | void OnTriggerEnter (Collider player) { 19 | if(player.gameObject.tag == "Player") 20 | { 21 | territoryUI.SetActive(true); 22 | territoryUI.GetComponent().text = territoryName; 23 | } 24 | } 25 | void OnTriggerExit(Collider player) 26 | { 27 | if(player.gameObject.tag == "Player") 28 | { 29 | territoryUI.SetActive(false); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /OnTriggerLoadLevelV2.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.SceneManagement; 5 | 6 | public class OnTriggerLoadLevelV2 : MonoBehaviour 7 | { 8 | 9 | public GameObject enterText; 10 | public string levelToLoad; 11 | 12 | void Start() 13 | { 14 | enterText.SetActive(false); 15 | } 16 | 17 | // Update is called once per frame 18 | void OnTriggerStay(Collider plyr) 19 | { 20 | if (plyr.gameObject.tag == "Player") 21 | { 22 | enterText.SetActive(true); 23 | if (Input.GetButtonDown("Use")) 24 | { 25 | SceneManager.LoadScene(levelToLoad); 26 | } 27 | } 28 | } 29 | void OnTriggerExit(Collider plyr) 30 | { 31 | if (plyr.gameObject.tag == "Player") 32 | { 33 | enterText.SetActive(false); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /UseInventory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityStandardAssets.Characters.ThirdPerson; 5 | 6 | public class UseInventory : MonoBehaviour 7 | { 8 | 9 | public bool stats; 10 | public bool item; 11 | 12 | public int tValue; 13 | public int hValue; 14 | 15 | GameObject inv; 16 | GameObject player; 17 | 18 | 19 | void Start() 20 | { 21 | inv = GameObject.FindWithTag("GameController"); 22 | player = GameObject.FindWithTag("Player"); 23 | } 24 | 25 | public void UseItem() 26 | { 27 | if (stats) 28 | { 29 | player.GetComponent().thirst += tValue; 30 | player.GetComponent().hunger += hValue; 31 | Destroy(gameObject); 32 | } 33 | 34 | if (item) 35 | { 36 | //use item 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ShowQuest2.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ShowQuest2 : MonoBehaviour { 6 | 7 | public GameObject questUI; 8 | public GameObject showQuest; 9 | 10 | bool entered = false; 11 | bool alreadyPlayed = false; 12 | 13 | public AudioClip sound; 14 | private AudioSource audio; 15 | 16 | void Start () { 17 | 18 | audio = GetComponent(); 19 | showQuest.SetActive(false); 20 | questUI.SetActive(false); 21 | } 22 | 23 | void OnTriggerEnter (Collider other) { 24 | if (other.tag == "Player" && !alreadyPlayed && !entered) 25 | { 26 | questUI.SetActive(true); 27 | showQuest.SetActive(true); 28 | audio.PlayOneShot(sound, 5); 29 | alreadyPlayed = true; 30 | entered = true; 31 | } 32 | } 33 | void OnTriggerExit(Collider other) 34 | { 35 | if(other.tag == "Player") 36 | { 37 | Destroy(showQuest); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DishonoredSpell.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class DishonoredSpell : MonoBehaviour { 5 | 6 | private RaycastHit lastRaycastHit; 7 | public AudioClip audioClip; 8 | public float range = 1000; 9 | 10 | private GameObject GetLookedAtObject() 11 | { 12 | Vector3 origin = transform.position; 13 | Vector3 direction = Camera.main.transform.forward; 14 | if (Physics.Raycast(origin, direction, out lastRaycastHit, range)) 15 | { 16 | return lastRaycastHit.collider.gameObject; 17 | } 18 | else 19 | { 20 | return null; 21 | } 22 | } 23 | 24 | private void TeleportToLookAt() 25 | { 26 | transform.position = lastRaycastHit.point + lastRaycastHit.normal * 1.5f; 27 | if (audioClip != null) 28 | AudioSource.PlayClipAtPoint(audioClip, transform.position); 29 | } 30 | void Update() 31 | { 32 | if (Input.GetKeyDown(KeyCode.Q)) 33 | if (GetLookedAtObject() != null) 34 | TeleportToLookAt(); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Vendor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Vendor : MonoBehaviour { 6 | 7 | Currency script; 8 | Inventory invScript; 9 | 10 | public GameObject vendorUI; 11 | 12 | public int cost; 13 | 14 | void Start() 15 | { 16 | vendorUI.SetActive(false); 17 | script = GameObject.FindWithTag("GameController").GetComponent(); 18 | invScript = GameObject.FindWithTag("GameController").GetComponent(); 19 | } 20 | void OnTriggerEnter() 21 | { 22 | vendorUI.SetActive(true); 23 | Cursor.visible = true; 24 | } 25 | 26 | // Update is called once per frame 27 | void OnTriggerExit () 28 | { 29 | vendorUI.SetActive(false); 30 | Cursor.visible = false; 31 | } 32 | public void BuyItem(GameObject objToCreate) 33 | { 34 | if (script.gold >= cost) 35 | { 36 | script.gold -= cost; 37 | GameObject i = Instantiate(objToCreate); 38 | i.transform.SetParent(invScript.invTab.transform); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Waypoints.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Waypoints : MonoBehaviour { 6 | 7 | public GameObject[] waypoints; 8 | public GameObject player; 9 | int current = 0; 10 | public float speed; 11 | float WPradius = 1; 12 | 13 | void Update () { 14 | if(Vector3.Distance(waypoints[current].transform.position, transform.position) < WPradius) 15 | { 16 | current = Random.Range(0,waypoints.Length); 17 | if (current >= waypoints.Length) 18 | { 19 | current = 0; 20 | } 21 | } 22 | transform.position = Vector3.MoveTowards(transform.position, waypoints[current].transform.position, Time.deltaTime * speed); 23 | 24 | } 25 | 26 | void OnTriggerEnter(Collider n) 27 | { 28 | if (n.gameObject == player) 29 | { 30 | player.transform.parent = transform; 31 | } 32 | } 33 | void OnTriggerExit(Collider n) 34 | { 35 | if (n.gameObject == player) 36 | { 37 | player.transform.parent = null; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Quest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Quest : MonoBehaviour { 5 | 6 | [SerializeField] 7 | bool showObjective = false; 8 | [SerializeField] 9 | Texture objective; 10 | [SerializeField] 11 | private int collision; 12 | 13 | void Start() 14 | { 15 | showObjective = false; 16 | } 17 | 18 | void OnTriggerEnter(Collider other) 19 | { 20 | if (other.gameObject.tag == "Player" && showObjective == false && collision == 0) 21 | showObjective = true; 22 | } 23 | void OnTriggerExit(Collider other) 24 | { 25 | if (other.gameObject.tag == "Player") 26 | showObjective = false; 27 | collision = 1; 28 | } 29 | void OnGUI() 30 | { 31 | if (showObjective == true) 32 | GUI.DrawTexture(new Rect(Screen.width / 1.5f, Screen.height / 1.4f, 178, 178), objective); 33 | } 34 | 35 | void Update() 36 | { 37 | if (Input.GetButton("ShowObj")&& collision == 1) 38 | { 39 | showObjective = true; 40 | } 41 | if (Input.GetButtonUp("ShowObj") && collision == 1) 42 | { 43 | showObjective = false; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ShowQuest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class ShowQuest : MonoBehaviour 6 | { 7 | public GameObject questUI; 8 | private int collision = 0; 9 | public AudioClip sound; 10 | private AudioSource audio; 11 | private bool alreadyPlayed = false; 12 | void Start() 13 | { 14 | audio = GetComponent(); 15 | questUI.SetActive(false); 16 | } 17 | 18 | void OnTriggerEnter(Collider other) 19 | { 20 | if (other.gameObject.tag == "Player" && questUI.activeSelf == false && collision == 0 && alreadyPlayed == false) 21 | questUI.SetActive(true); 22 | audio.PlayOneShot(sound, 5); 23 | alreadyPlayed = true; 24 | } 25 | void OnTriggerExit(Collider other) 26 | { 27 | if (other.gameObject.tag == "Player") 28 | questUI.SetActive(false); 29 | collision = 1; 30 | } 31 | void Update() 32 | { 33 | if (Input.GetButton("Q") && collision == 1) 34 | { 35 | questUI.SetActive(true); 36 | if (Input.GetButtonDown("Q")) 37 | { 38 | audio.PlayOneShot(sound, 5); 39 | } 40 | } 41 | if (Input.GetButtonUp("Q") && collision == 1) 42 | { 43 | questUI.SetActive(false); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /ShowWeapon.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ShowWeapon : MonoBehaviour 5 | { 6 | [SerializeField] 7 | public GameObject item1; 8 | [SerializeField] 9 | public GameObject item2; 10 | public bool showItem1; 11 | public bool showItem2; 12 | // Use this for initialization 13 | void Start() 14 | { 15 | showItem1 = false; 16 | showItem2 = false; 17 | } 18 | 19 | // Update is called once per frame 20 | void Update() 21 | { 22 | if (showItem1 == false) 23 | { 24 | item1.SetActive(false); 25 | } 26 | if (showItem1 == true) 27 | { 28 | item1.SetActive(true); 29 | } 30 | if (showItem2 == false) 31 | { 32 | item2.SetActive(false); 33 | } 34 | if (showItem2 == true) 35 | { 36 | item2.SetActive(true); 37 | } 38 | if (Input.GetKeyDown(KeyCode.Alpha1) && showItem1 == false) 39 | { 40 | showItem1 = true; 41 | showItem2 = false; 42 | } 43 | if(Input.GetKeyDown(KeyCode.Alpha2)&& showItem2 == false) 44 | { 45 | showItem2 = true; 46 | showItem1 = false; 47 | } 48 | if (Input.GetKeyDown(KeyCode.R)) 49 | { 50 | showItem2 = false; 51 | showItem1 = false; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /PickUp.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class PickUp : MonoBehaviour { 6 | 7 | Animator anim; 8 | Inventory invScript; 9 | 10 | public bool money; 11 | public int moneyAmount; 12 | Currency moneyScript; 13 | 14 | public bool item; 15 | public GameObject itemIcon; 16 | 17 | bool pickedUp = false; 18 | 19 | 20 | // Use this for initialization 21 | void Start () { 22 | 23 | anim = GameObject.FindWithTag("Player").GetComponent(); 24 | moneyScript = GameObject.FindWithTag("GameController").GetComponent(); 25 | invScript = GameObject.FindWithTag("GameController").GetComponent(); 26 | } 27 | 28 | // Update is called once per frame 29 | void OnTriggerStay(Collider player) { 30 | if (player.tag == "Player") 31 | { 32 | if (Input.GetKeyDown(KeyCode.E) && !pickedUp) 33 | { 34 | pickedUp = true; 35 | StartCoroutine("PlayAnim"); 36 | } 37 | } 38 | } 39 | 40 | IEnumerator PlayAnim() 41 | { 42 | anim.SetTrigger("pickup"); 43 | yield return new WaitForSeconds(1); 44 | if (money) 45 | { 46 | moneyScript.gold += moneyAmount; 47 | Destroy(gameObject); 48 | } 49 | else if (item) 50 | { 51 | GameObject i = Instantiate(itemIcon); 52 | i.transform.SetParent(invScript.invTab.transform); 53 | Destroy(gameObject); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /EnterVehicle.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using UnityStandardAssets.Vehicles.Car; 4 | 5 | public class EnterVehicle : MonoBehaviour 6 | { 7 | private bool inVehicle = false; 8 | CarUserControl vehicleScript; 9 | public GameObject guiObj; 10 | GameObject player; 11 | 12 | 13 | void Start() 14 | { 15 | vehicleScript = GetComponent(); 16 | player = GameObject.FindWithTag("Player"); 17 | guiObj.SetActive(false); 18 | } 19 | 20 | // Update is called once per frame 21 | void OnTriggerStay(Collider other) 22 | { 23 | if (other.gameObject.tag == "Player" && inVehicle == false) 24 | { 25 | guiObj.SetActive(true); 26 | if (Input.GetKey(KeyCode.E)) 27 | { 28 | guiObj.SetActive(false); 29 | player.transform.parent = gameObject.transform; 30 | vehicleScript.enabled = true; 31 | player.SetActive(false); 32 | inVehicle = true; 33 | } 34 | } 35 | } 36 | void OnTriggerExit(Collider other) 37 | { 38 | if (other.gameObject.tag == "Player") 39 | { 40 | guiObj.SetActive(false); 41 | } 42 | } 43 | void Update() 44 | { 45 | if (inVehicle == true && Input.GetKey(KeyCode.F)) 46 | { 47 | vehicleScript.enabled = false; 48 | player.SetActive(true); 49 | player.transform.parent = null; 50 | inVehicle = false; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /ShootAuto.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | using UnityEngine; 5 | using System.Collections; 6 | 7 | public class ShootAuto : MonoBehaviour 8 | { 9 | public Transform ballPos; 10 | public Rigidbody Ball; 11 | static float timeMin = 10; 12 | static float timeMax = 15; 13 | float forceAmount = 13000; 14 | public GameObject effect; 15 | 16 | 17 | void SpawnBall() 18 | { 19 | Rigidbody ballRigid; 20 | if ((Ball != null) && (ballPos != null)) 21 | { 22 | ballRigid = Instantiate(Ball, ballPos.position, ballPos.rotation) as Rigidbody; 23 | Instantiate(effect, ballPos.position, ballPos.rotation); 24 | if (ballRigid != null) 25 | { 26 | ballRigid.AddForce(ballPos.forward * forceAmount); 27 | } 28 | else 29 | { 30 | Debug.LogWarning("The instantiated item does not contain a Rigidbody"); 31 | } 32 | } 33 | else 34 | { 35 | if ((Ball == null)) 36 | { 37 | Debug.LogWarning("Ball has not been assigned. Please assign the Ball"); 38 | } 39 | if (ballPos == null) 40 | { 41 | Debug.LogWarning("ballPos has not been assigned. Please assign the ballPos"); 42 | } 43 | } 44 | } 45 | 46 | void Start() 47 | { 48 | float timeToSpawn = Random.Range(timeMin, timeMax); 49 | InvokeRepeating("SpawnBall", timeToSpawn, Random.Range(3, 7)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /ThrowObject.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ThrowObject : MonoBehaviour 5 | { 6 | public Transform player; 7 | public Transform playerCam; 8 | public float throwForce = 10; 9 | bool hasPlayer = false; 10 | bool beingCarried = false; 11 | public AudioClip[] soundToPlay; 12 | private AudioSource audio; 13 | public int dmg; 14 | private bool touched = false; 15 | 16 | void Start() 17 | { 18 | audio = GetComponent(); 19 | } 20 | 21 | void Update() 22 | { 23 | float dist = Vector3.Distance(gameObject.transform.position, player.position); 24 | if (dist <= 2.5f) 25 | { 26 | hasPlayer = true; 27 | } 28 | else 29 | { 30 | hasPlayer = false; 31 | } 32 | if (hasPlayer && Input.GetButtonDown("Use")) 33 | { 34 | GetComponent().isKinematic = true; 35 | transform.parent = playerCam; 36 | beingCarried = true; 37 | } 38 | if (beingCarried) 39 | { 40 | if (touched) 41 | { 42 | GetComponent().isKinematic = false; 43 | transform.parent = null; 44 | beingCarried = false; 45 | touched = false; 46 | } 47 | if (Input.GetMouseButtonDown(0)) 48 | { 49 | GetComponent().isKinematic = false; 50 | transform.parent = null; 51 | beingCarried = false; 52 | GetComponent().AddForce(playerCam.forward * throwForce); 53 | RandomAudio(); 54 | } 55 | else if (Input.GetMouseButtonDown(1)) 56 | { 57 | GetComponent().isKinematic = false; 58 | transform.parent = null; 59 | beingCarried = false; 60 | } 61 | } 62 | } 63 | void RandomAudio() 64 | { 65 | if (audio.isPlaying){ 66 | return; 67 | } 68 | audio.clip = soundToPlay[Random.Range(0, soundToPlay.Length)]; 69 | audio.Play(); 70 | 71 | } 72 | void OnTriggerEnter() 73 | { 74 | if (beingCarried) 75 | { 76 | touched = true; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /ThirdPersonCharacter.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | 4 | namespace UnityStandardAssets.Characters.ThirdPerson 5 | { 6 | [RequireComponent(typeof(Rigidbody))] 7 | [RequireComponent(typeof(CapsuleCollider))] 8 | [RequireComponent(typeof(Animator))] 9 | public class ThirdPersonCharacter : MonoBehaviour 10 | { 11 | [SerializeField] float m_MovingTurnSpeed = 360; 12 | [SerializeField] float m_StationaryTurnSpeed = 180; 13 | [SerializeField] float m_JumpPower = 12f; 14 | [Range(1f, 4f)][SerializeField] float m_GravityMultiplier = 2f; 15 | [SerializeField] float m_RunCycleLegOffset = 0.2f; //specific to the character in sample assets, will need to be modified to work with others 16 | [SerializeField] float m_MoveSpeedMultiplier = 1f; 17 | [SerializeField] float m_AnimSpeedMultiplier = 1f; 18 | [SerializeField] float m_GroundCheckDistance = 0.1f; 19 | 20 | Rigidbody m_Rigidbody; 21 | Animator m_Animator; 22 | bool m_IsGrounded; 23 | float m_OrigGroundCheckDistance; 24 | const float k_Half = 0.5f; 25 | float m_TurnAmount; 26 | float m_ForwardAmount; 27 | Vector3 m_GroundNormal; 28 | float m_CapsuleHeight; 29 | Vector3 m_CapsuleCenter; 30 | CapsuleCollider m_Capsule; 31 | bool m_Crouching; 32 | 33 | public float health = 100; 34 | public float hunger = 100; 35 | public float thirst = 100; 36 | 37 | public float deathRate; 38 | public float thirstRate; 39 | public float hungerRate; 40 | 41 | public Slider Hbar; 42 | public Slider Tbar; 43 | public Slider healthBar; 44 | 45 | 46 | void Start() 47 | { 48 | m_Animator = GetComponent(); 49 | m_Rigidbody = GetComponent(); 50 | m_Capsule = GetComponent(); 51 | m_CapsuleHeight = m_Capsule.height; 52 | m_CapsuleCenter = m_Capsule.center; 53 | 54 | m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ; 55 | m_OrigGroundCheckDistance = m_GroundCheckDistance; 56 | } 57 | 58 | void Update() 59 | { 60 | healthBar.value = health; 61 | Hbar.value = hunger; 62 | Tbar.value = thirst; 63 | 64 | hunger = hunger - (hungerRate * Time.deltaTime); 65 | thirst = thirst - (thirstRate * Time.deltaTime); 66 | 67 | if (health <= 0) 68 | { 69 | health = 0; 70 | m_Animator.SetTrigger("dead"); 71 | gameObject.GetComponent().enabled = false; 72 | } 73 | if(hunger <= 0 || thirst <= 0) 74 | { 75 | health = health - (deathRate * Time.deltaTime); 76 | } 77 | if(hunger <= 0) 78 | { 79 | hunger = 0; 80 | } 81 | if (thirst <= 0) 82 | { 83 | thirst = 0; 84 | } 85 | } 86 | 87 | 88 | public void Move(Vector3 move, bool crouch, bool jump) 89 | { 90 | 91 | // convert the world relative moveInput vector into a local-relative 92 | // turn amount and forward amount required to head in the desired 93 | // direction. 94 | if (move.magnitude > 1f) move.Normalize(); 95 | move = transform.InverseTransformDirection(move); 96 | CheckGroundStatus(); 97 | move = Vector3.ProjectOnPlane(move, m_GroundNormal); 98 | m_TurnAmount = Mathf.Atan2(move.x, move.z); 99 | m_ForwardAmount = move.z; 100 | 101 | ApplyExtraTurnRotation(); 102 | 103 | // control and velocity handling is different when grounded and airborne: 104 | if (m_IsGrounded) 105 | { 106 | HandleGroundedMovement(crouch, jump); 107 | } 108 | else 109 | { 110 | HandleAirborneMovement(); 111 | } 112 | 113 | ScaleCapsuleForCrouching(crouch); 114 | PreventStandingInLowHeadroom(); 115 | 116 | // send input and other state parameters to the animator 117 | UpdateAnimator(move); 118 | } 119 | 120 | 121 | void ScaleCapsuleForCrouching(bool crouch) 122 | { 123 | if (m_IsGrounded && crouch) 124 | { 125 | if (m_Crouching) return; 126 | m_Capsule.height = m_Capsule.height / 2f; 127 | m_Capsule.center = m_Capsule.center / 2f; 128 | m_Crouching = true; 129 | } 130 | else 131 | { 132 | Ray crouchRay = new Ray(m_Rigidbody.position + Vector3.up * m_Capsule.radius * k_Half, Vector3.up); 133 | float crouchRayLength = m_CapsuleHeight - m_Capsule.radius * k_Half; 134 | if (Physics.SphereCast(crouchRay, m_Capsule.radius * k_Half, crouchRayLength, Physics.AllLayers, QueryTriggerInteraction.Ignore)) 135 | { 136 | m_Crouching = true; 137 | return; 138 | } 139 | m_Capsule.height = m_CapsuleHeight; 140 | m_Capsule.center = m_CapsuleCenter; 141 | m_Crouching = false; 142 | } 143 | } 144 | 145 | void PreventStandingInLowHeadroom() 146 | { 147 | // prevent standing up in crouch-only zones 148 | if (!m_Crouching) 149 | { 150 | Ray crouchRay = new Ray(m_Rigidbody.position + Vector3.up * m_Capsule.radius * k_Half, Vector3.up); 151 | float crouchRayLength = m_CapsuleHeight - m_Capsule.radius * k_Half; 152 | if (Physics.SphereCast(crouchRay, m_Capsule.radius * k_Half, crouchRayLength, Physics.AllLayers, QueryTriggerInteraction.Ignore)) 153 | { 154 | m_Crouching = true; 155 | } 156 | } 157 | } 158 | 159 | 160 | void UpdateAnimator(Vector3 move) 161 | { 162 | // update the animator parameters 163 | m_Animator.SetFloat("Forward", m_ForwardAmount, 0.1f, Time.deltaTime); 164 | m_Animator.SetFloat("Turn", m_TurnAmount, 0.1f, Time.deltaTime); 165 | m_Animator.SetBool("Crouch", m_Crouching); 166 | m_Animator.SetBool("OnGround", m_IsGrounded); 167 | if (!m_IsGrounded) 168 | { 169 | m_Animator.SetFloat("Jump", m_Rigidbody.velocity.y); 170 | } 171 | 172 | // calculate which leg is behind, so as to leave that leg trailing in the jump animation 173 | // (This code is reliant on the specific run cycle offset in our animations, 174 | // and assumes one leg passes the other at the normalized clip times of 0.0 and 0.5) 175 | float runCycle = 176 | Mathf.Repeat( 177 | m_Animator.GetCurrentAnimatorStateInfo(0).normalizedTime + m_RunCycleLegOffset, 1); 178 | float jumpLeg = (runCycle < k_Half ? 1 : -1) * m_ForwardAmount; 179 | if (m_IsGrounded) 180 | { 181 | m_Animator.SetFloat("JumpLeg", jumpLeg); 182 | } 183 | 184 | // the anim speed multiplier allows the overall speed of walking/running to be tweaked in the inspector, 185 | // which affects the movement speed because of the root motion. 186 | if (m_IsGrounded && move.magnitude > 0) 187 | { 188 | m_Animator.speed = m_AnimSpeedMultiplier; 189 | } 190 | else 191 | { 192 | // don't use that while airborne 193 | m_Animator.speed = 1; 194 | } 195 | } 196 | 197 | 198 | void HandleAirborneMovement() 199 | { 200 | // apply extra gravity from multiplier: 201 | Vector3 extraGravityForce = (Physics.gravity * m_GravityMultiplier) - Physics.gravity; 202 | m_Rigidbody.AddForce(extraGravityForce); 203 | 204 | m_GroundCheckDistance = m_Rigidbody.velocity.y < 0 ? m_OrigGroundCheckDistance : 0.01f; 205 | } 206 | 207 | 208 | void HandleGroundedMovement(bool crouch, bool jump) 209 | { 210 | // check whether conditions are right to allow a jump: 211 | if (jump && !crouch && m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Grounded")) 212 | { 213 | // jump! 214 | m_Rigidbody.velocity = new Vector3(m_Rigidbody.velocity.x, m_JumpPower, m_Rigidbody.velocity.z); 215 | m_IsGrounded = false; 216 | m_Animator.applyRootMotion = false; 217 | m_GroundCheckDistance = 0.1f; 218 | } 219 | } 220 | 221 | void ApplyExtraTurnRotation() 222 | { 223 | // help the character turn faster (this is in addition to root rotation in the animation) 224 | float turnSpeed = Mathf.Lerp(m_StationaryTurnSpeed, m_MovingTurnSpeed, m_ForwardAmount); 225 | transform.Rotate(0, m_TurnAmount * turnSpeed * Time.deltaTime, 0); 226 | } 227 | 228 | 229 | public void OnAnimatorMove() 230 | { 231 | // we implement this function to override the default root motion. 232 | // this allows us to modify the positional speed before it's applied. 233 | if (m_IsGrounded && Time.deltaTime > 0) 234 | { 235 | Vector3 v = (m_Animator.deltaPosition * m_MoveSpeedMultiplier) / Time.deltaTime; 236 | 237 | // we preserve the existing y part of the current velocity. 238 | v.y = m_Rigidbody.velocity.y; 239 | m_Rigidbody.velocity = v; 240 | } 241 | } 242 | 243 | 244 | void CheckGroundStatus() 245 | { 246 | RaycastHit hitInfo; 247 | #if UNITY_EDITOR 248 | // helper to visualise the ground check ray in the scene view 249 | Debug.DrawLine(transform.position + (Vector3.up * 0.1f), transform.position + (Vector3.up * 0.1f) + (Vector3.down * m_GroundCheckDistance)); 250 | #endif 251 | // 0.1f is a small offset to start the ray from inside the character 252 | // it is also good to note that the transform position in the sample assets is at the base of the character 253 | if (Physics.Raycast(transform.position + (Vector3.up * 0.1f), Vector3.down, out hitInfo, m_GroundCheckDistance)) 254 | { 255 | m_GroundNormal = hitInfo.normal; 256 | m_IsGrounded = true; 257 | m_Animator.applyRootMotion = true; 258 | } 259 | else 260 | { 261 | m_IsGrounded = false; 262 | m_GroundNormal = Vector3.up; 263 | m_Animator.applyRootMotion = false; 264 | } 265 | } 266 | } 267 | } 268 | --------------------------------------------------------------------------------