- Home /
Question by
Jaidan · Feb 22, 2015 at 03:59 PM ·
error messagenot working
Why isnt my code working? C# [NOOB]
I need to know why my code is not working:
using UnityEngine;
using System.Collections;
public class ShipController : MonoBehaviour{
public float turnspeed = 5f;
public float speed = 5f;
public float trueSpeed = 0f;
public float strafeSpeed = 5f;
void Update () {
float roll = Input.GetAxis ("Roll");
float pitch = Input.GetAxis ("Pitch");
float yaw = Input.GetAxis ("Yaw");
float strafe = Vector3 (Input.GetAxis ("Horizontal") * strafeSpeed * Time.deltaTime, Input.GetAxis ("Vertical") * strafeSpeed * Time.deltaTime, 0);
float power = Input.GetAxis ("Power");
if (trueSpeed < 10f && trueSpeed > -3f) {
trueSpeed += power;
}
if (trueSpeed > 10f) {
trueSpeed = 9.99f;
}
if (trueSpeed < -3f) {
trueSpeed = -2.99f;
}
if (Input.GetKey ("backspace")) {
trueSpeed = 0;
}
rigidbody.AddRelativeTorque (pitch * turnspeed * Time.deltaTime, yaw * turnspeed * Time.deltaTime, roll * turnspeed * Time.deltaTime);
rigidbody.AddRelativeForce (0f, 0f, trueSpeed * speed * Time.deltaTime);
rigidbody.AddRelativeForce (strafe);
}
}
Errors:
Assets/ShipController.cs(16,32): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
Assets/ShipController.cs(35,27): error CS1502: The best overloaded method match for UnityEngine.Rigidbody.AddRelativeForce(UnityEngine.Vector3)' has some invalid arguments Assets/ShipController.cs(35,27): error CS1503: Argument
#1' cannot convert float' expression to type
UnityEngine.Vector3'
Comment
Best Answer
Answer by tanoshimi · Feb 22, 2015 at 04:06 PM
float strafe = Vector3 (Input.GetAxis ("Horizontal") * strafeSpeed * Time.deltaTime, Input.GetAxis ("Vertical") * strafeSpeed * Time.deltaTime, 0);
should be:
Vector3 strafe = new Vector3 (Input.GetAxis ("Horizontal") * strafeSpeed * Time.deltaTime, Input.GetAxis ("Vertical") * strafeSpeed * Time.deltaTime, 0);