Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by FLC · Mar 31, 2011 at 10:03 AM · cameraguicounterammo

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];
     }*/
 }

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Meltdown · Mar 31, 2011 at 10:50 AM 2
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

When i shoot, the next shoot will have the bullet half way down the screen!!! 1 Answer

I want a HitMark(GUI) system like in Crysis-CoD that indicates where i am hit from and also a Camera/Screen shake effect 3 Answers

Unity2D - Camera in exported game is zoomed out compared to unity game preview HELP PLEASE! 2 Answers

Puttings GUI's between objects 1 Answer

How do I mask off specific parts from a plane or cube? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges