- Home /
GUI ammo counter not linked to player
(I am not a programmer, sorry for every big fault I should write)
I would link a GUI ammo counter script (similar to the rocket GUI counter in the FPS tutorial) not to the player, but to another actor in the same scene: in short, I have, in the same level, one camera (top camera) which acts as player, shooting on the ground (and has an ammo counter script), but it isn't tagged as player; I need to maintain this actor/camera in the same level of the player which is only allowed to switch from top camera to fps camera, but in the fp camera can't use the 'weapon' which can use only from top camera.
My problem is: GUI ammo counter script, modified from FPSplayer.js in the FPS tutorial, is now linked to the main actor in the top camera (I need the shooting from top, not from FP view), not to the player; and it seems to works (weapon works, ammo counter works), but doesn't update the ammo conter texures. Is the problem the linking to a game object not tagged as player? I link here code for the launcher and the modified FPSplayer. Thank you very much, hoping to been clear (my english sucks as well as my programmer skills -__-).
this is the launcher.js
var projectile : Rigidbody;
var speed = 20;
var ammoCount = 20;
function Update()
{
if( Input.GetButtonDown( "Fire1" ) ) if (ammoCount > 0)
{
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity =
transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
ammoCount--;
}
}
This is the script (js) modified from FPSPlayer script which should address the DrawRockets.js script (all the relative textures and objects in the inspector work and have been setup as in the FPS tutorial)
var rocketGUI : DrawRockets; private var rocketLauncher : launcher; var rocketTextures : Texture[];
function Awake () { rocketLauncher = GetComponent(launcher); }
function UpdateGUI () {
// Update rocket gui
// This is changed from the tutorial PDF. You need to assign the 20 Rocket textures found in the GUI/Rockets folder
// to the RocketTextures property.
if (rocketLauncher) {
rocketGUI.UpdateRockets(rocketLauncher.ammoCount);
/*if (rocketTextures.Length == 0) {
Debug.LogError ("The tutorial was changed with Unity 2.0 - You need to assign the 20 Rocket textures found in the GUI/Rockets folder to the RocketTextures property.");
} else {
rocketGUI.texture = rocketTextures[rocketLauncher.ammoCount];
}*/
}
}
Please re-read your question and edit it correctly so all the code is placed properly in a code tag. The quickest way to chase people away from readinf your question is to show code that isn't formatted properly :p