- Home /
Question by
Broskie524 · Aug 15, 2014 at 07:08 PM ·
gunshootreload
Wrote a script for Shooting, reloading and to display the AMMO in a GUIText
This is the script, When ever I start the game It says "Assets/shoot.js(17,22): BCE0018: The name 'ammotext' does not denote a valid type('not found')" I have no Idea what to do >.>
var sound : AudioClip; //ie_shot_gun-liminalace-770179786 soundClip
var reloadSound: AudioClip; //reload soundClip
var BulletSpeed = 100; //force of bullets being shot
var projectile : Rigidbody; //bullet prefab goes here
var bullets = 30; //amount of bullets per "clip"
var totalBullets = 60; //total amount of bullets we have available
var reloadTime = 3; //time to reload
var reloadAmount = 10;
var ammo : ammotext; //GUI text for our bullet/ammo count
function Update () {
Fire ();
Reload ();
}
function Fire () {
if(bullets > 0) { //if we have at least 1 bullet then we can fire
if (Input.GetButtonDown("Fire1")) {
var clone : Rigidbody;// Instantiate the projectile at the position and rotation of this transform
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3.forward * BulletSpeed);// Give the cloned object an initial velocity along the current
AudioSource.PlayClipAtPoint(sound, transform.position, 1); // object's Z axis
bullets -=1; //subtracts one bullet per fire sequence
}
}
}
function Reload () {
if(bullets < 1) { //if we have less than 1 bullet then we can reload
if(Input.GetKeyDown("r")) {
AudioSource.PlayClipAtPoint(reloadSound, transform.position, 1); //plays reload soundclip
yield WaitForSeconds(reloadTime); //waits for "reloadTime" before adding bullets
bullets += reloadAmount; //adds 3 bullets to our "clip"
totalBullets -= reloadAmount; //subtracts 3 bullets from our totalBullets amount
}
}
}
function OnGUI () {
ammo.text = "bullets: " + bullets + "/" + totalBullets.ToString();
}
Comment
Best Answer
Answer by Landern · Aug 15, 2014 at 07:09 PM
Did you define a class called "ammotext"?
var ammo : ammotext; //GUI text for our bullet/ammo count
On this line, you are saying the variable "ammo" is of type ammotext. You may find this confusing, did you mean to put:
var ammo : GUIText; //GUI text for our bullet/ammo count
Thanks man It shoots but wont show the GUIText and wont reload Im going to try to fix it
Your answer
Follow this Question
Related Questions
No Reload Script Works 1 Answer
3rd Person Gun Aim 1 Answer
I want to be able to make a good shoot script that actually works. 0 Answers
Troubles With A Shoot Script 1 Answer
Gun script reload problems 3 Answers