|
|
|
using UnityEngine;
|
|
|
|
using CnControls;
|
|
|
|
public class RocketMovement : MonoBehaviour
|
|
|
|
{
|
|
|
|
public static RocketMovement Instance;
|
|
|
|
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;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
void rocketStarter()
|
|
|
|
{
|
|
|
|
rocketStarted = true;
|
|
|
|
}
|
|
|
|
void FixedUpdate()
|
|
|
|
{
|
|
|
|
if (rocketStarted)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void SpeedIncreaser()
|
|
|
|
{
|
|
|
|
upSpeed += 1f;
|
|
|
|
}
|
|
|
|
}
|