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
0
Question by Dmellott · Feb 07, 2013 at 08:40 AM · ontriggerentertriggers

Decreasing a variable with triggers?

I am using Javascript to make it so that when the player touches the fire in my scene they lose "Armor Points." However, when I step into the Trigger box the number does not change. Again, I am using Javascript and these are they two scripts I am using to try to achieve what I am going for. Any help would be greatly appreciated!

This section is my main cameraScript. It is attached to the Main Camera Controller and is where I declare my static var armor.

static var ammo;

static var enemyhealth;

static var armor;

function Start() {

ammo= 6;

enemyhealth= 9;

}

function OnGUI() {

GUI.skin = customSkin;

GUI.Box(Rect(20,130,130,75),"Armor Points 100");

GUI.Box(Rect(384,50,275,50),"Enemy Health "+ enemyhealth);

GUI.Box(Rect(20,20,185,75),"Health Points 14/14");

GUI.Box(Rect(500,450,190,75),"Ammo Count "+ ammo);

if(enemyhealth>=9){

GUI.DrawTexture(Rect(390,75,25,25), myLogo1);

GUI.DrawTexture(Rect(420,75,25,25), myLogo1);

GUI.DrawTexture(Rect(450,75,25,25), myLogo1);

GUI.DrawTexture(Rect(480,75,25,25), myLogo1);

GUI.DrawTexture(Rect(510,75,25,25), myLogo1);

GUI.DrawTexture(Rect(540,75,25,25), myLogo1);

GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=8){ GUI.DrawTexture(Rect(420,75,25,25), myLogo1);

GUI.DrawTexture(Rect(450,75,25,25), myLogo1);

GUI.DrawTexture(Rect(480,75,25,25), myLogo1);

GUI.DrawTexture(Rect(510,75,25,25), myLogo1);

GUI.DrawTexture(Rect(540,75,25,25), myLogo1);

GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=7){ GUI.DrawTexture(Rect(450,75,25,25), myLogo1);

GUI.DrawTexture(Rect(480,75,25,25), myLogo1);

GUI.DrawTexture(Rect(510,75,25,25), myLogo1);

GUI.DrawTexture(Rect(540,75,25,25), myLogo1);

GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=6){ GUI.DrawTexture(Rect(480,75,25,25), myLogo1);

GUI.DrawTexture(Rect(510,75,25,25), myLogo1);

GUI.DrawTexture(Rect(540,75,25,25), myLogo1);

GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=5){ GUI.DrawTexture(Rect(510,75,25,25), myLogo1);

GUI.DrawTexture(Rect(540,75,25,25), myLogo1);

GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=4){ GUI.DrawTexture(Rect(540,75,25,25), myLogo1);

GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=3){ GUI.DrawTexture(Rect(570,75,25,25), myLogo1);

GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=2){ GUI.DrawTexture(Rect(600,75,25,25), myLogo1);

GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth>=1){ GUI.DrawTexture(Rect(630,75,25,25), myLogo1); }

if(enemyhealth<=0){ GUI.Box(Rect(600,200,200,40),"YOU WIN!"); }

if(ammo>=6){

GUI.DrawTexture(Rect(505,490,30,30), myLogo);

GUI.DrawTexture(Rect(535,490,30,30), myLogo);

GUI.DrawTexture(Rect(565,490,30,30), myLogo);

GUI.DrawTexture(Rect(595,490,30,30), myLogo);

GUI.DrawTexture(Rect(625,490,30,30), myLogo);

GUI.DrawTexture(Rect(655,490,30,30), myLogo); }

if(ammo>=5){

GUI.DrawTexture(Rect(535,490,30,30), myLogo);

GUI.DrawTexture(Rect(565,490,30,30), myLogo);

GUI.DrawTexture(Rect(595,490,30,30), myLogo);

GUI.DrawTexture(Rect(625,490,30,30), myLogo);

GUI.DrawTexture(Rect(655,490,30,30), myLogo); }

if(ammo>=4){

GUI.DrawTexture(Rect(565,490,30,30), myLogo);

GUI.DrawTexture(Rect(595,490,30,30), myLogo);

GUI.DrawTexture(Rect(625,490,30,30), myLogo);

GUI.DrawTexture(Rect(655,490,30,30), myLogo); }

if(ammo>=3){

GUI.DrawTexture(Rect(595,490,30,30), myLogo);

GUI.DrawTexture(Rect(625,490,30,30), myLogo);

GUI.DrawTexture(Rect(655,490,30,30), myLogo); }

if(ammo>=2){

GUI.DrawTexture(Rect(625,490,30,30), myLogo);

GUI.DrawTexture(Rect(655,490,30,30), myLogo); }

if(ammo>=1){

GUI.DrawTexture(Rect(655,490,30,30), myLogo); }

if(ammo<=0){

GUI.Box(Rect(500,400,200,40),"RELOAD!"); }

} function Update(){

if( Input.GetKeyDown("r") ){

ammo=6; } if(cameraScript.enemyhealth<=0){

Application.LoadLevel(2); } }

This second script is for the trigger box that currently is not decreasing the number when you step into the trigger box.

static var armor;

function OnTriggerEnter()

{

cameraScript.armor-=1;

}

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 Fattie · Feb 07, 2013 at 08:40 AM 0
Share

try unityGE$$anonymous$$S.com for excellent beginner articles

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter2D working only on original prefab and not on its copies 1 Answer

OnTriggerEnter is not working! I have tried absolutely everything I can think of. 1 Answer

Peculiar multiple-rigidbody-trigger problem. 2 Answers

How to make Parent object's script ignore trigger component on children 1 Answer

Can not get OnTriggerEnter and OnCollisionEnter to work!? 1 Answer


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