Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(PlayerMotor))]
- public class PlayerController : MonoBehaviour
- {
- public Interactable focus;
- public LayerMask moveMask;
- Camera cam;
- PlayerMotor motor;
- void Start()
- {
- cam = Camera.main;
- motor = GetComponent<PlayerMotor>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButton(0))
- {
- Ray moveray = cam.ScreenPointToRay(Input.mousePosition);
- RaycastHit movehit;
- if (Physics.Raycast(moveray,out movehit,100, moveMask ))
- {
- Debug.Log ("Moving to " + movehit.collider.name +" " + movehit.point);
- motor.MoveToPoint(movehit.point);
- //Move to hit
- //Stop focusing Objects
- RemoveFocus();
- }
- }
- if (Input.GetMouseButton(1))
- {
- Ray actray = cam.ScreenPointToRay(Input.mousePosition);
- RaycastHit actHit;
- if (Physics.Raycast(actray,out actHit,100))
- {
- Debug.Log ("Looks Like a " + actHit.collider.name +" " + actHit.point);
- Interactable interactable = actHit.collider.GetComponent<Interactable>();
- if (interactable != null)
- {
- SetFocus(interactable);
- }
- }
- }
- }
- void SetFocus(Interactable newFocus)
- {
- if (newFocus != focus)
- {
- if (focus != null)
- {focus.OnDeFocused();}
- focus = newFocus;
- motor.FollowTarget(newFocus);
- }
- newFocus.OnFocused(transform);
- }
- void RemoveFocus()
- {
- if (focus != null)
- {focus.OnDeFocused();}
- focus = null;
- motor.StopFollowTarget();
- }
- }
Add Comment
Please, Sign In to add comment