From a0312d35ca90c7524e0b761f14a48c4cc2f6fe2a Mon Sep 17 00:00:00 2001 From: darrelmarek Date: Wed, 13 Sep 2017 17:29:22 -0500 Subject: [PATCH] Mouse implementation 1 --- Project Undercover/Assets/Scenes/scene.unity | 9 +++++- .../Assets/Scripts/PlayerController.cs | 29 +++++++++++++++++++ .../Assets/Scripts/SimpleNPCBehavior.cs | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Project Undercover/Assets/Scenes/scene.unity b/Project Undercover/Assets/Scenes/scene.unity index 96ce232..2456cfc 100644 --- a/Project Undercover/Assets/Scenes/scene.unity +++ b/Project Undercover/Assets/Scenes/scene.unity @@ -299,6 +299,11 @@ Prefab: propertyPath: m_Name value: NPC (3) objectReference: {fileID: 0} + - target: {fileID: 54771552521138126, guid: b25e969032ebb1f4089308db11ee93b1, + type: 2} + propertyPath: m_IsKinematic + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: b25e969032ebb1f4089308db11ee93b1, type: 2} m_IsPrefabParent: 0 @@ -399,7 +404,7 @@ Rigidbody: m_AngularDrag: 0.05 m_UseGravity: 1 m_IsKinematic: 1 - m_Interpolate: 0 + m_Interpolate: 1 m_Constraints: 0 m_CollisionDetection: 0 --- !u!114 &966385057 @@ -413,6 +418,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3c9e5b8e36b3b0747811ece9fa00437a, type: 3} m_Name: m_EditorClassIdentifier: + particle: {fileID: 1057615597006810, guid: b25e969032ebb1f4089308db11ee93b1, type: 2} + TransitionSpeed: 1 --- !u!4 &984138133 stripped Transform: m_PrefabParentObject: {fileID: 4550573785341638, guid: b25e969032ebb1f4089308db11ee93b1, diff --git a/Project Undercover/Assets/Scripts/PlayerController.cs b/Project Undercover/Assets/Scripts/PlayerController.cs index e58244c..62c8c93 100644 --- a/Project Undercover/Assets/Scripts/PlayerController.cs +++ b/Project Undercover/Assets/Scripts/PlayerController.cs @@ -1,7 +1,18 @@ using UnityEngine; +using System.Collections; public class PlayerController : MonoBehaviour { + public GameObject particle; + public float TransitionSpeed; + private Rigidbody rigi; + private Vector3 velocity = Vector3.zero; + + void Start() + { + rigi = GetComponent(); + } + void Update() { var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f; @@ -9,5 +20,23 @@ public class PlayerController : MonoBehaviour transform.Rotate(0, x, 0); transform.Translate(0, 0, z); + + RaycastHit hit; + if (Input.GetButtonDown("Fire1")) { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + if (Physics.Raycast(ray, out hit)) { + Vector3 wantedPos = hit.point; + wantedPos.y = 0.5f; + Instantiate (particle, wantedPos, transform.rotation); + } + } + if (Input.GetButtonDown("Fire2")) { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + if (Physics.Raycast(ray, out hit)) { + Vector3 wantedPos = hit.point; + wantedPos.y = 0.5f; + transform.position = Vector3.Lerp (transform.position, wantedPos, Time.deltaTime * TransitionSpeed); + } + } } } \ No newline at end of file diff --git a/Project Undercover/Assets/Scripts/SimpleNPCBehavior.cs b/Project Undercover/Assets/Scripts/SimpleNPCBehavior.cs index 3178f60..1221233 100644 --- a/Project Undercover/Assets/Scripts/SimpleNPCBehavior.cs +++ b/Project Undercover/Assets/Scripts/SimpleNPCBehavior.cs @@ -10,7 +10,7 @@ public class SimpleNPCBehavior : MonoBehaviour void Start() { - target.Set(0.0f, 0.5f, 0.0f); + target.Set (4.0f - (8.0f * Random.value), 0.5f, 4.0f - (8.0f * Random.value)); rigi = GetComponent(); }