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 junkfreak · Jun 11, 2014 at 10:43 AM · pickupitemhealth

got a kind of health(battery) pickup, that doesnt work

so i got 2 scripts one for on my gamemanger (empty object) and the other for the pick up, when i pick it up it should send a message that my curBattery = 100, but it doesnt do anything? could anybody help me.

pickup using UnityEngine; using System.Collections;

public class Pick: MonoBehaviour {

 public BatteryLife batteryLife;
 //public float maxBattery = 100.0f;
 //public float curBattery = 100.0f;
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }

 float curBattery = 100 ;
 //float maxBattery = 0;
 void OnTriggerEnter(Collider coll)
 {
     if(coll.gameObject.tag == "pickUp")
     {
         coll.gameObject.SetActive (false);
         //curBattery=maxBattery;
         batteryLife.SendMessage("Drain",curBattery,SendMessageOptions.DontRequireReceiver);
     }
 }

}

gamemanager

using UnityEngine; using System.Collections;

public class BatteryLife : MonoBehaviour { public float maxBattery = 100.0f; public float curBattery = 100.0f; public float batteryDrainSpeed = 500.0f; public string battery = "Battery: ";

 void Start () {
     
 }
 
 
 void Update () {
     //curBattery = Mathf.Clamp(curBattery - (Time.deltaTime * (1000 / batteryDrainSpeed)),0.0f,maxBattery);
     Drain ();

     if (curBattery <= 0)
     {
         Death ();
     }
 }
 
 void OnGUI() {
     GUI.Box(new Rect(140, 175, Screen.width / 10 /(maxBattery / curBattery), 25), battery + curBattery + "/" + maxBattery);

 }

 void Death(){
     if (curBattery <= 0)
     {
         Application.LoadLevel("Death");
     }

     void Drain(){
         curBattery = Mathf.Clamp(curBattery - (Time.deltaTime * (1000 / batteryDrainSpeed)),0.0f,maxBattery);
     }
         
 }


}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by korbul · Jun 11, 2014 at 01:11 PM

Make sure that your entities respect this table http://answers.unity3d.com/storage/attachments/2050-interactionmatrix.png

You can cross rows with columns in that table, if there is a Y in the cell then you will have OnTriggerEnter callback for those two objects.

secondly, make sure the other collider has a "pickUp" tag set on it.

 if(coll.gameObject.tag == "pickUp")

also Death() function does not have its brackets in order.

 void Death(){
     if (curBattery <= 0)
     {
        Application.LoadLevel("Death");
     }
  
     void Drain(){
        curBattery = Mathf.Clamp(curBattery - (Time.deltaTime * (1000 / batteryDrainSpeed)),0.0f,maxBattery);
     }
  
 }

it looks like Drain() is inside Death()

Hope these suggestions help

Comment
Add comment · Show 1 · Share
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 junkfreak · Jun 11, 2014 at 04:54 PM 0
Share

no it still doesnt seem to be working andi solved the death thing, accidentily deleted it.

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Very Simple Pickup Issue 0 Answers

pick up item collision 2 Answers

Picking Up AND Hold Onto Items using Raycasting (Bug) 2 Answers

Add Health on Pickup to Decaying Health,Make a collision with an object add health 2 Answers

Trigger event from ground and activate the Object-child in the Camera 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