Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- using UnityStandardAssets.Characters.FirstPerson;
- public class Player : MonoBehaviour
- {
- public AudioClip[] audioClip;
- int rayLength = 5;
- bool Pickup_Pressed = false;
- float delay = 3.0f;
- public FirstPersonController fpscontroller;
- public WeaponSwitch wepswitch;
- bool HasTommy = false;
- bool HasAxe = false;
- public int foodLevel = 0;
- String foodLevelText = "0";
- // Use this for initialization
- void Start ()
- {
- }
- // Update is called once per frame
- void Update ()
- {
- PickUpItems();
- CheckWhatGun();
- WeaponSwitchingScroll();
- }
- void OnTriggerEnter(Collider Col)
- {
- if (Col.tag == "weapon")
- {
- Debug.Log("You picked a weapon!");
- PlaySound(1);
- Destroy(Col.gameObject);
- wepswitch.Gun_Switch_Tommygun.SetActive(true);
- HasTommy = true;
- }
- }
- public void PlaySound(int clip)
- {
- AudioSource audio = GetComponent<AudioSource>();
- audio.clip = audioClip[clip];
- audio.Play();
- }
- void PickUpItems()
- {
- RaycastHit hit;
- var fwd = transform.TransformDirection(Vector3.forward);
- if (Physics.Raycast(transform.position, fwd, out hit, rayLength))
- {
- if (hit.collider.gameObject.tag == "food")
- {
- if (Input.GetKeyDown("e"))
- {
- if(Pickup_Pressed == false)
- {
- Destroy(hit.collider.gameObject);
- StartCoroutine(MyMethod());
- PlaySound(0);
- Pickup_Pressed = true;
- }
- Destroy(hit.collider.gameObject, delay);
- }
- }
- if (hit.collider.gameObject.tag == "axe")
- {
- if (Input.GetKeyDown("e"))
- {
- wepswitch.Gun_Switch_Axe.SetActive(true);
- HasAxe = true;
- PlaySound(1);
- Destroy(hit.collider.gameObject);
- }
- }
- }
- }
- IEnumerator MyMethod()
- {
- Debug.Log("Before Waiting 2 seconds");
- fpscontroller.m_WalkSpeed = 0;
- yield return new WaitForSeconds(3);
- Debug.Log("After Waiting 2 Seconds");
- fpscontroller.m_WalkSpeed = 5;
- foodLevel += 5;
- }
- void CheckWhatGun()
- {
- if (HasTommy == true)
- {
- if(HasAxe == true)
- {
- wepswitch.Gun_Switch_Tommygun.SetActive(false);
- HasTommy = false;
- }
- }
- if (HasAxe == true)
- {
- if(HasTommy == true)
- {
- wepswitch.Gun_Switch_Axe.SetActive(false);
- HasTommy = true;
- }
- }
- }
- void WeaponSwitchingScroll()
- {
- if(HasAxe == true && HasTommy == true)
- {
- if (Input.GetKeyDown("q"))
- {
- wepswitch.Gun_Switch_Tommygun.SetActive(false);
- }
- else if (Input.GetKeyDown("f"))
- {
- wepswitch.Gun_Switch_Axe.SetActive(false);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement