79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SpaceshipControllerSolo : MonoBehaviour
|
|
{
|
|
public static SpaceshipControllerSolo player {get; private set;}
|
|
[SerializeField]private float MovingSpeed = 0.2f;
|
|
[SerializeField]private float BoostMultiplier = 2;
|
|
[SerializeField]private float TurningSmoothness = 0.1f;
|
|
[SerializeField]private float TrailIncrementRate = 0.5f;
|
|
[SerializeField]private TrailMgrSolo trailMgr;
|
|
public bool isBoosting { get; private set; }
|
|
public Joystick joystick;
|
|
[SerializeField] private Transform body;
|
|
public int MoonsCollected {get; private set;}
|
|
void Awake(){
|
|
player = this;
|
|
}
|
|
void Start()
|
|
{
|
|
if (joystick == null)
|
|
{
|
|
joystick = FindObjectOfType<Joystick>();
|
|
}
|
|
}
|
|
float curSpeed => isBoosting ? MovingSpeed * BoostMultiplier : MovingSpeed;
|
|
public Vector2 JoyInput => joystick.input;
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
body.Translate(new Vector3(0, curSpeed), body);
|
|
if (JoyInput != Vector2.zero)
|
|
{
|
|
Turn(JoyInput);
|
|
}
|
|
}
|
|
|
|
void Turn(Vector2 input)
|
|
{
|
|
body.rotation = Quaternion.Lerp(body.rotation, getTurnAngle(input), TurningSmoothness * input.magnitude);
|
|
}
|
|
Quaternion getTurnAngle(Vector2 input)
|
|
{
|
|
var angle1 = Mathf.Atan2(-input.y, -input.x) * Mathf.Rad2Deg;
|
|
return Quaternion.AngleAxis(angle1 + 90, Vector3.forward);
|
|
}
|
|
|
|
public void CollectPickup(PickupItemSolo.PickupType type){
|
|
switch(type){
|
|
case PickupItemSolo.PickupType.Moon:
|
|
AudioManager.instnace.CollectMoon(1,1);
|
|
trailMgr.trail.time += TrailIncrementRate;
|
|
MoonsCollected++;
|
|
break;
|
|
|
|
case PickupItemSolo.PickupType.Star:
|
|
AudioManager.instnace.CollectMoon(1,1);
|
|
|
|
|
|
trailMgr.trail.time += TrailIncrementRate/2f;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void TrailCollided(Collider2D hit){
|
|
// Debug.Log($"I got hit with this : {hit.name}");
|
|
if(hit.GetComponent<SpaceshipBot>()!=null){
|
|
hit.GetComponent<SpaceshipBot>().Die();
|
|
}
|
|
}
|
|
|
|
public void Die(){
|
|
TutorialManager.instance.MinigameFailed();
|
|
Destroy(gameObject);
|
|
}
|
|
}
|