- Home /
Question by
blankfaced · Nov 28, 2012 at 09:30 PM ·
helicopter
Error with my C# script for my helicopter
Okay, I have a error with my C# script (In unity.) It says,
"Assets/FlightScript.cs(26,18): error CS0103: The name `Ship' does not exist in the current context"
And here is the code below.
using UnityEngine;
using System.Collections;
public class FlightScript : MonoBehaviour {
void Start () {
}
public float AmbientSpeed = 100.0f;
public float RotationSpeed = 200.0f;
void UpdateFunction() {
Quaternion AddRot = Quaternion.identity;
float roll = 0;
float pitch = 0;
float yaw = 0;
roll = Input.GetAxis("Roll") * (Time.deltaTime * RotationSpeed);
pitch = Input.GetAxis("Pitch") * (Time.deltaTime * RotationSpeed);
yaw = Input.GetAxis("Yaw") * (Time.deltaTime * RotationSpeed);
AddRot.eulerAngles = new Vector3(-pitch, yaw, -roll);
rigidbody.rotation *= AddRot;
Vector3 AddPos = Vector3.forward;
AddPos = Ship.rigidbody.rotation * AddPos;
rigidbody.velocity = AddPos * (Time.deltaTime * AmbientSpeed);
}
}
Comment
Answer by Chronos-L · Nov 29, 2012 at 04:52 AM
There is no variable declared as Ship in your code.
public Class FlightScript : MonoBehaviour {
public GameObject Ship;
...
}
Answer by toum · Nov 29, 2012 at 12:11 AM
Your 'Ship' object has not been declared.
You probably want to access GameObject property by calling "Ship.rigidbody.rotation".
If your "ship" is the game object where your script is attached. Then replace by:
AddPos = gameObject.rigidbody.rotation * AddPos;
Your Ship variable must be assigned with a GameObject instance if you want to access rigidbody property:
http://docs.unity3d.com/Documentation/ScriptReference/GameObject-rigidbody.html
Tom