Player Controls
This commit is contained in:
8
Assets/Game/Scripts/Minigame.meta
Normal file
8
Assets/Game/Scripts/Minigame.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a164a3dcd856bbf09abadbbe2c75629d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Game/Scripts/Minigame/CameraFollower.cs
Normal file
21
Assets/Game/Scripts/Minigame/CameraFollower.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollower : MonoBehaviour
|
||||
{
|
||||
public bool autoOffset = true;
|
||||
public Vector3 offset;
|
||||
public Transform target;
|
||||
public float smoothness = 0.1f;
|
||||
void Start()
|
||||
{
|
||||
offset = transform.position - target.position;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, target.position + offset, smoothness * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/CameraFollower.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/CameraFollower.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b20032ec7edc76b0ca5b2759bc19363f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class joystick : MonoBehaviour
|
||||
public class Joystick : MonoBehaviour
|
||||
{
|
||||
public bool DissappearOnEnd = true;
|
||||
private Vector3 defaultPosition;
|
||||
42
Assets/Game/Scripts/Minigame/PlayerController.cs
Normal file
42
Assets/Game/Scripts/Minigame/PlayerController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public Transform body;
|
||||
public float movingSpeed = 0.1f;
|
||||
public float turningSmoothFactor = 0.1f;
|
||||
public Joystick joystick;
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
body.Translate(new Vector3(0, movingSpeed), body);
|
||||
if (joystick.input != Vector2.zero)
|
||||
{
|
||||
//Turn
|
||||
var angle1 = Mathf.Atan2(-joystick.input.y, -joystick.input.x) * Mathf.Rad2Deg;
|
||||
body.rotation = Quaternion.Lerp(body.rotation, Quaternion.AngleAxis(angle1 + 90, Vector3.forward), turningSmoothFactor * joystick.input.magnitude);
|
||||
}
|
||||
}
|
||||
|
||||
public float Angle(Vector2 vector2)
|
||||
{
|
||||
return 360 - (Mathf.Atan2(vector2.x, vector2.y) * Mathf.Rad2Deg * Mathf.Sign(vector2.x));
|
||||
}
|
||||
|
||||
|
||||
//Auto assign default variables [Editor only]
|
||||
void OnValidate()
|
||||
{
|
||||
if (body == null)
|
||||
{
|
||||
body = transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Game/Scripts/Minigame/PlayerController.cs.meta
Normal file
11
Assets/Game/Scripts/Minigame/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9292398ab503e2abb1f0dd8acf58f9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user