Advertisement
renderbydavid

LOOKcntrl

Oct 29th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.38 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class PlayerLook : MonoBehaviour
  7. {
  8.     RaycastHit hit;
  9.     [HideInInspector]
  10.     public float rotX, rotY, mouseX, mouseY;
  11.     public float clampAngle;
  12.     public Transform PlayerT;
  13.     bool interacting;
  14.     [HideInInspector]
  15.     public int Seeds;
  16.     [HideInInspector]
  17.     public Image InteractIndicator, BloodBar;
  18.     private void Start()
  19.     {
  20.         BloodBar = GameObject.Find("PlayerBloodBar").GetComponent<Image>();
  21.         InteractIndicator = GameObject.Find("InteractIndicator").GetComponent<Image>();
  22.         Cursor.lockState = CursorLockMode.Locked;
  23.  
  24.     }
  25.     void Update()
  26.     {
  27.  
  28.         if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 3, 1 << 0))
  29.         {
  30.             if(hit.transform.tag == "Pumpkin")
  31.             {
  32.                 if(hit.transform.GetComponent<Pumpkin>().ReadyToHarvest)
  33.                 {
  34.                     //interacting = true;
  35.                     InteractIndicator.enabled = true;
  36.                     InteractIndicator.sprite = hit.transform.GetComponent<Pumpkin>().MyIndicator;
  37.                     if (Input.GetKeyDown(KeyCode.E))
  38.                     {
  39.                         hit.transform.GetComponent<Pumpkin>().HarvestMe();
  40.                     }
  41.                 }
  42.                 else
  43.                 {
  44.                     if(Seeds >= 10)
  45.                     {
  46.                         if (Input.GetKeyDown(KeyCode.E))
  47.                         {
  48.                             Seeds -= 10;
  49.                             hit.transform.GetComponent<Pumpkin>().HealPumpkin();
  50.                         }
  51.                     }
  52.                     else
  53.                     {
  54.                         InteractIndicator.enabled = false;
  55.                     }
  56.                 }
  57.             }
  58.             else
  59.             {
  60.                 if(hit.transform.tag == "Interact")
  61.                 {
  62.                     //interacting = true;
  63.                     InteractIndicator.enabled = true;
  64.                     InteractIndicator.sprite = hit.transform.GetComponent<Interactable>().MyIndicator;
  65.                     if (Input.GetKeyDown(KeyCode.E))
  66.                     {
  67.                         hit.transform.GetComponent<Interactable>().Invoke(hit.transform.GetComponent<Interactable>().Interact, 0);
  68.                     }
  69.                 }
  70.                 else
  71.                 {
  72.                     InteractIndicator.enabled = false;
  73.                 }
  74.             }
  75.         }
  76.         else
  77.         {
  78.             InteractIndicator.enabled = false;
  79.             //if (interacting)
  80.             //{
  81.             //    interacting = false;
  82.             //    InteractIndicator.enabled = false;
  83.             //}
  84.         }
  85.  
  86.         mouseX = Input.GetAxis("Mouse X") * Time.deltaTime * 35f;
  87.         mouseY = Input.GetAxis("Mouse Y") * Time.deltaTime * 35f;
  88.  
  89.         rotX += mouseY;
  90.         rotY += mouseX;
  91.         rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);
  92.  
  93.         //Quaternion localRotation = Quaternion.Euler(-rotX, 0, 0);
  94.  
  95.         transform.rotation = Quaternion.Euler(-rotX, PlayerT.transform.localEulerAngles.y, 0);
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement