void Update () {
if (CrossPlatformInputManager.GetButton ("Fire") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
}
if (CrossPlatformInputManager.GetButton ("FireAft") && Time.time > nextFireAft) {
nextFireAft = Time.time + fireRateAft;
Instantiate (shotAft, shotSpawnAft.position, shotSpawnAft.rotation);
}
Vector3 moveVec = new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal"), CrossPlatformInputManager.GetAxis ("Vertical"));// * moveForce;
if (CrossPlatformInputManager.GetAxis("Horizontal") > 0)
{
transform.eulerAngles = new Vector3(0, 90, 0);
}
else if(CrossPlatformInputManager.GetAxis("Horizontal") < 0)
{
transform.eulerAngles = new Vector3(0, -90, 0);
}
}
I know Use This Edit of your script:
//I use javascript more so this might contain Errors
using UnityEngine;
using System.Collections;
public float turnSpeed;
void Update () {
public float turn = 0;
if (CrossPlatformInputManager.GetButton ("Fire") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
}
if (CrossPlatformInputManager.GetButton ("FireAft") && Time.time > nextFireAft) {
nextFireAft = Time.time + fireRateAft;
Instantiate (shotAft, shotSpawnAft.position, shotSpawnAft.rotation);
}
Vector3 moveVec = new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal"), CrossPlatformInputManager.GetAxis ("Vertical"));// * moveForce;
if (CrossPlatformInputManager.GetAxis("Horizontal") > 0)
{
turn += 1;
}
else if(CrossPlatformInputManager.GetAxis("Horizontal") < 0)
{
turn -= 1;
}
transform.eulerAngles = new Vector3(0, turn, 0);
}
@OsmiousH
Thanks for your reply. Your solution caused the ship to continue rotating, instead of stopping when facing the opposite direction, which was the problem I had had with some other attempts. However, after some tweaking, using your ‘turn +/-’ suggestion, it has finally worked nicely. Many thanks! Here is the updated code…
public float turn = -180;
// Use this for initialization
void Start () {
myBody = this.GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
if (CrossPlatformInputManager.GetButton ("Fire") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
Instantiate (shot, shotSpawn.position, shotSpawn.rotation);
}
if (CrossPlatformInputManager.GetButton ("FireAft") && Time.time > nextFireAft) {
nextFireAft = Time.time + fireRateAft;
Instantiate (shotAft, shotSpawnAft.position, shotSpawnAft.rotation);
}
Vector3 moveVec = new Vector3 (CrossPlatformInputManager.GetAxis ("Horizontal"), CrossPlatformInputManager.GetAxis ("Vertical"));
if (CrossPlatformInputManager.GetAxis("Horizontal") > 0.5 && turn > -180)
{
turn -= 30;
}
else if(CrossPlatformInputManager.GetAxis("Horizontal") < -0.5 && turn < 0)
{
turn += 30;
}
transform.eulerAngles = new Vector3(0, (turn - 90), 0);
}