You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FlyingFred/Assets/Scripts/RocketMovement.cs

66 lines
1.8 KiB
C#

using UnityEngine;
using CnControls;
public class RocketMovement : MonoBehaviour
{
public static RocketMovement Instance;
1 month ago
public float upSpeed;
[Range(0.01f, 0.1f)]
public float controllerSpeed;
[SerializeField]
Vector2 newPos = Vector2.zero;
[SerializeField]
Vector2 oldPos = Vector2.zero;
[SerializeField]
Vector2 resPos = Vector2.zero;
public SimpleJoystick Joystick;
1 month ago
public bool rocketStarted;
private void Awake()
{
Instance = this;
}
private void Start()
{
GameManager.DifficultyIncreased.AddListener(() => SpeedIncreaser());
//rocketStarter();
Invoke(nameof(rocketStarter),3f);
Invoke(nameof(JoystickEnabler),4f);
}
void JoystickEnabler()
{
Joystick.gameObject.SetActive(true);
1 month ago
}
void rocketStarter()
{
rocketStarted = true;
}
void FixedUpdate()
{
1 month ago
if (rocketStarted)
1 month ago
{
1 month ago
if (Joystick.isActive)
{
resPos.x = oldPos.x + CnInputManager.GetAxis("Horizontal");
resPos.y = oldPos.y + CnInputManager.GetAxis("Vertical");
resPos.x = Mathf.Clamp(resPos.x, -1, 1);
resPos.y = Mathf.Clamp(resPos.y, -1, 1);
newPos.x = Mathf.Lerp(newPos.x, resPos.x, controllerSpeed);
newPos.y = Mathf.Lerp(newPos.y, resPos.y, controllerSpeed);
transform.position = new Vector3(newPos.x, transform.position.y, -newPos.y);
oldPos.x = newPos.x;
oldPos.y = newPos.y;
}
else
{
oldPos = resPos;
//oldPos = newPos;
}
transform.Translate(upSpeed * Time.fixedDeltaTime * Vector3.up);
1 month ago
}
}
void SpeedIncreaser()
{
1 month ago
upSpeed += 1f;
}
}