I need someone to help me change this script so that players won’t control each other and it works for everyone. And yes, I know I spelled “Maneuver” wrong when I created the script. It’s too late to change it now.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class ShipManeuver : MonoBehaviour {
public float maxSpeed = 22.5f;
public float rotSpeed = 180f;
public Sprite NormalLightBlue;
public Sprite LightBluefireanim1;
public GameObject Player;
public GameObject Player2;
public AudioSource deathsound;
public GameObject destroy2;
float shipBoundaryRadius = 0.5f;
void Start () {
}
public void Update () {
// ROTATE the ship.
// Grab our rotation quaternion
Quaternion rot = transform.rotation;
// Grab the Z euler angle
float z = rot.eulerAngles.z;
// Change the Z angle based on input
z -= Input.GetAxis("LJoystickr") * rotSpeed * Time.deltaTime;
// Recreate the quaternion
rot = Quaternion.Euler( 0, 0, z );
// Feed the quaternion into our rotation
transform.rotation = rot;
// MOVE the ship.
Vector3 pos = transform.position;
Vector3 velocity = new Vector3(0, Input.GetAxis("LJoystickl") * maxSpeed * Time.deltaTime, 0);
pos += rot * velocity;
// RESTRICT the player to the camera's boundaries!
// Finally, update our position!!
transform.position = pos;
if(Input.GetAxis("LJoystickl") != 0)
{
Player.GetComponent<SpriteRenderer>().sprite = LightBluefireanim1;
}
else
{
Player.GetComponent<SpriteRenderer>().sprite = NormalLightBlue;
}
if(Player.GetComponent<Boosting>().boostuse == 1)
{
StartCoroutine(BoostCooldown());
Player.GetComponent<Boosting>().boostuse = 0;
}
}
IEnumerator BoostCooldown()
{
//Print the time of when the function is first called.
Debug.Log("Started boost use Coroutine at timestamp : " + Time.time);
Player.GetComponent<Boosting>().enabled = false;
//yield on a new YieldInstruction that waits for 5 seconds.
yield return new WaitForSeconds(10);
Player.GetComponent<Boosting>().enabled = true;
//After we have waited 5 seconds print the time again.
//Print the time of when the function is first called.
Debug.Log("Finished boost use Coroutine at timestamp : " + Time.time);
}
void OnTriggerEnter2D(Collider2D other)
{
if(other.gameObject.tag == "pilot2")
{
StartCoroutine(holdon());
}
}
IEnumerator holdon()
{
//Print the time of when the function is first called.
Debug.Log("Started Coroutine 2 at timestamp : " + Time.time);
yield return new WaitForSeconds(1);
deathsound.Play(0);
Destroy(Player2);
destroy2.SetActive(true);
//Print the time of when the function is first called.
Debug.Log("Finished Coroutine 2 at timestamp : " + Time.time);
}
}