I’m getting the following error when I run my Unity project:
Here is an edited version of the code that it I believe it is refering to:
What I can’t figure out is what is causing the error.
It looks like Unity is telling me that the object declaration for “instantiatedProjectile” doesn’t match the instance parameters, but it is clearly a Rigidbody type in both. And, I can confirm that I have attached a Rigidbody (prefab) in the parameters panel.
I’ve resisted the urge to clean it up so you can see the whole magillah.
var projectile : Rigidbody; // "projectilce" is a GameObject
//
var missileLife = 10.0; // destoy missile ten seconds after launch
var fireRate = 0.5; // wait half a second before alowing next missile launch
var initialSpeed = 20.0;
//
private var launcherOffset = 5; // missile up offset form launcher at launch
private var nextFire = 0.0;
//
var ammoCount;
var barGUIWidth;
var ammoStart = 20.0;
//
var barGUI : GUITexture;
var hudXTextureIndex = 0;
var hudXTexture1 : Texture2D;
var hudXTexture2 : Texture2D;
function Start ()
{
ammoCount = ammoStart; // set ammo counter to start amount
barGUIWidth = barGUI.pixelInset.width;
}
function Update () {
// fire processing
if (Input.GetButton ("Fire1") Time.time > nextFire) {
// reset fire timer
nextFire = Time.time + fireRate;
// create a new projectile, use the same position and rotation as the Launcher.
// var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
var instantiatedProjectile : Rigidbody;
instantiatedProjectile = Instantiate (projectile, transform.position, transform.rotation);
// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
// instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));
// Ignore collisions between the missile and the character controller
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
// destroy this missile instance after a set time
Destroy (instantiatedProjectile, missileLife);
// cycle texture index
hudXTextureIndex++;
if (hudXTextureIndex == 2) {hudXTextureIndex=0;}
// Debug.Log(hudXTextureIndex);
// update texture
if (hudXTextureIndex == 1) {
barGUI.texture = hudXTexture1;
}
else {
barGUI.texture = hudXTexture2;
}
} // end fire processing
} // end update
Try making a really simple scene with only a game object that has the script attached. and a cube with rigidbody that you then set to be the projectile.
Does that work?
With the script you posted, that worked fine for me.