Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Taragon · Jun 04, 2011 at 10:09 PM · guitimerpickuplerpz3dplatformtutorial

Timer script Update with Pickup

I am modifying the Lerpz tutorial to basically have a timer that updates when the player picks up the object. What is happening now is that the GUI starts with 20 seconds on the clock (adjusted in the inspector). However, every time the player picks up an object this GUI and variable, "emission" needs be updated by variable "forbiddenfruit". This is not happening. What is happening is that variable "emission" is constantly being added on never ceasing. I have attached the Emitter Script, an object of the particle system which is a child of the player as well as the ThirdpersonStatus script which includes the forbiddenfruit variable. Forbiddenfruit work perfectly as I've tested the output. Code: var emission = 0.1f; var emissionMod = 0.1f; var other : ThirdPersonStatus;

 function Awake () {
     other = FindObjectOfType(ThirdPersonStatus);
     if (other == null) {
     print("you haven't addd the component to the gameobject");    
     //emission +=other.forbiddenfruit;
 
 }
 }
 function Update () {
 if (emission > 0.1) {
     emission -= ((emissionMod - other.forbiddenfruit)* Time.deltaTime);
 print("float value = " + emission);
 particleEmitter.minEmission = emission;
 particleEmitter.maxEmission = emission;
 }
 else emission = 0;
 }
 Code:
 // ThirdPersonStatus: Handles the player's state machine.
 
 // Keeps track of inventory, health, lives, etc.
 
 
 var health : int = 6;
 var maxHealth : int = 6;
 var lives : int;
 var currentmultiplier = 10;
 
 var forbiddenfruit : int;
 var inc = 2;
 var interactiontime : int;
 
 // sound effects.
 var struckSound: AudioClip;
 var deathSound: AudioClip;
 
 private var levelStateMachine : LevelStatus;        // link to script that handles the level-complete sequence.
 
 private var remainingItems : int;    // total number to pick up on this level. Grabbed from LevelStatus.
 
 
 function Awake()
 {
     
     levelStateMachine = FindObjectOfType(LevelStatus);
     if (!levelStateMachine)
         Debug.Log("No link to Level Status");
     
     remainingItems = levelStateMachine.itemsNeeded;
     remainingGems  = levelStateMachine.gemsNeeded;
 }
 
 function Update()
 {
     if (lives <= 0 && Application.loadedLevel == 0)
     {
         Application.LoadLevel("TheGame");
         
     }
     
 }
 
 // Utility function used by HUD script:
 function GetRemainingItems() : int
 {
     //return remainingItems;
     return forbiddenfruit;
 }
 
 function GetTimeLeft() : int
 {
     return interactiontime;
 }
 
 /*Window example*/
 
 function AddLife (powerUp : int) // FUEL CELL COUNT - THE CURRENTMULTIPLIER SHOULD NOT BE USED
 {
     lives -= powerUp;
     forbiddenfruit +=powerUp * 10;
     //Debug.Log(forbiddenfruit);
     //timeinc+=lives;
 }
 
 function FoundItem (numFound: int)
 {
     forbiddenfruit +=numFound * currentmultiplier;
     //Debug.Log(forbiddenfruit);
     //forbiddenfruit+= numFound * currentmultiplier;
         
 // NOTE: We are deliberately not clamping this value to zero. 
 // This allows for levels where the number of pickups is greater than the target number needed. 
 // This also lets us speed up the testing process by temporarily reducing the collecatbles needed. 
 // Our HUD will clamp to zero for us.
     
 }
 
 //function ChangeOxygen () 
 //{
 //changeoxygenscript = FindObjectOfType(Emitter);
 //changeoxygenscript.emission=changeoxy;
 //changeoxy+=forbiddenfruit;
 //}
 
 function Increase () {
 
     if(Application.loadedLevel == 0){
     currentmultiplier = 10;
     //Debug.Log(currentmultiplier);
     }
     else if(Application.loadedLevel == 1){
     currentmultiplier = 20;
     //Debug.Log(currentmultiplier);
     }
     else if(Application.loadedLevel == 2){
     currentmultiplier = 30;
     //Debug.Log(currentmultiplier);
     }
     else if(Application.loadedLevel == 3){
     currentmultiplier = 40;
     //Debug.Log(currentmultiplier);
     }
     else{
         inc+=0;
 }
 }
     
 function FalloutDeath ()
 {
     Die();
     return;
 }
 
 function Die ()
 {
     // play the death sound if available.
     if (deathSound)
     {
         AudioSource.PlayClipAtPoint(deathSound, transform.position);
 
     }
     
     if(lives <= 0)
         Application.LoadLevel("TheGame");    
     
     // If we've reached here, the player still has lives remaining, so respawn.
     respawnPosition = Respawn.currentRespawn.transform.position;
     Camera.main.transform.position = respawnPosition - (transform.forward * 4) + Vector3.up;    // reset camera too
     // Hide the player briefly to give the death sound time to finish...
     SendMessage("HidePlayer");
     
     // Relocate the player. We need to do this or the camera will keep trying to focus on the (invisible) player where he's standing on top of the FalloutDeath box collider.
     transform.position = respawnPosition + Vector3.up;
 
     yield WaitForSeconds(1.6);    // give the sound time to complete. 
     
     // (NOTE: "HidePlayer" also disables the player controls.)
 
     SendMessage("ShowPlayer");    // Show the player again, ready for...    
     // ... the respawn point to play it's particle effect
     Respawn.currentRespawn.FireEffect ();
 }
 function LevelCompleted() 
 { 
  levelStateMachine.LevelCompleted(); 
 }
Comment
Add comment
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

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

2 People are following this question.

avatar image avatar image

Related Questions

3Dplatformer tutorial GUI script - adding a timer GUI 0 Answers

Timer script & game hud 0 Answers

Instantiating GUI text after 2nd object is destroyed 1 Answer

Lerpz Escapes question 1 Answer

Understanding the Pickup script in Lerpz tutorial 2 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