Spaceship Script not working?
I watched an online tutorial on how to make a script for space flight controls. After I finish and saved the C# script and went back to unity it said I had numerous name space and phrasing errors? I'm pretty new to coding all together and I've been trying to find the solution for 2 days now with no luck. This is the script I am using bellow:
var turnspeed = 6.0; var speed = 10.0; private var trueSpeed = 0.0; var strafeSpeed = 5.0; function Update () { var roll = Input.GetAxis("Roll"); var pitch = Input.GetAxis("Pitch"); var yaw = Input.GetAxis("Yaw"); var strafe = Vector3(Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime, Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime, 0); var power = Input.GetAxis("Power"); //Truespeed controls if (trueSpeed < 10 && trueSpeed > -3){ trueSpeed += power; } if (trueSpeed > 10){ trueSpeed = 9.99; } if (trueSpeed < -3){ trueSpeed = -2.99; } if (Input.GetKey("backspace")){ trueSpeed = 0; } rigidbody.AddRelativeTorque(pitch*turnspeed*Time.deltaTime, yaw*turnspeed*Time.deltaTime, roll*turnspeed*Time.deltaTime); rigidbody.AddRelativeForce(0,0,trueSpeed*speed*Time.deltaTime); rigidbody.AddRelativeForce(strafe); }
please format your code properly - it's very difficult to read in your post.
when you're asking about errors, it's a really good idea to paste them - including line numbers... which is why it's important to format the code ;)
did you enter the code exactly as in the tutorial?
are you sure that it's c# and not unityscript?
Sorry I will resubmit the script in the correct order. And I am pretty sure it is C# that's what the video said as least. here is the script don't know why numbers aren't co$$anonymous$$g up they don't on my visual studio either.
using UnityEngine; using System.Collections;
public class Flying1 : $$anonymous$$onoBehaviour {
public class CustomflightControler : $$anonymous$$onoBehaviour
{
public float turnspeed = 5.0f;
public float speed = 5.0f;
public float trueSpeed = 0.0f;
public bool trueSpeedShiftLOC$$anonymous$$ = true;
public float trueSpeedPosShift = 0.0f;
public float trueSpeedNegShift = 0.0f;
public bool LOC$$anonymous$$Set$$anonymous$$ax$$anonymous$$in = false;
public float Set$$anonymous$$ax = 10.00f;
public float Set$$anonymous$$in = -3.00f;
public float strafeSpeed = 5.0f;
public float powerShift = 0.0f;
public float rollShift = 0.0f;
public float yawShift = 0.0f;
public float pitchShift = 0.0f;
public Vector3 strafeShift = new Vector3(0, 0, 0);
void Update()
{
if (LOC$$anonymous$$Set$$anonymous$$ax$$anonymous$$in) Set$$anonymous$$in = Set$$anonymous$$ax;
if (trueSpeedShiftLOC$$anonymous$$) trueSpeedNegShift = trueSpeedPosShift;
float roll = Input.GetAxis(“Roll”) + rollShift;
float pitch = Input.GetAxis(“$$anonymous$$ch”) + pitchShift;
float yaw = Input.GetAxis(“Yaw”) + yawShift;
Vector3 strafe = new Vector3((Input.GetAxis(“Horizontal”) * strafeSpeed * Time.deltaTime), Input.GetAxis(“Vertical”) * strafeSpeed * Time.deltaTime, 0);
float power = Input.GetAxis(“Power”) + powerShift;
//Truespeed controls
if (trueSpeed(-3 - trueSpeedNegShift))
{
trueSpeed += power;
}
if (trueSpeed > Set$$anonymous$$ax + trueSpeedPosShift)
{
trueSpeed = (Set$$anonymous$$ax - .01f) + trueSpeedPosShift;
}
if (trueSpeed < (Set$$anonymous$$in - trueSpeedNegShift))
{
trueSpeed = (Set$$anonymous$$in - .01f) – trueSpeedNegShift;
}
if (Input.Get$$anonymous$$ey("backspace")) { trueSpeed = 0; }
rigidbody.AddRelativeTorque(pitch * turnspeed * Time.deltaTime, yaw * turnspeed * Time.deltaTime, roll * turnspeed * Time.deltaTime);
rigidbody.AddRelativeForce(0, 0, trueSpeed * speed * Time.deltaTime);
rigidbody.AddRelativeForce(strafe + strafeShift);
}
}
try editing the original question, and capture all of the code.
and don't forget to post the error messages too - they're important ;)