• 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 kiko · Aug 20, 2011 at 07:14 AM · score

score not add in the gui text

hi guys i really need help in this script: when my player hits the bamboo it never add into the gui text.what is the cause of the problem for this? its only apply in the ThirdPersonStatus.

Gui text script:

static var text : String; var Score : int = 0;

function Update () {

guiText.text= text;

}

function OnGUI(){ GUI.Label(Rect(10, 10, 100, 20),Score.ToString());

}

function OnTriggerEnter(other : Collider){ Debug.Log("score" + Score);

if(other.gameObject.CompareTag("bamboo"))

{ Destroy(gameObject); Debug.Log("collide"); } }

thirdpersonstatus:

enum PickupType { Health = 0, bamboo= 1 ,clock= 2} var pickupType = PickupType.bamboo; static var amount = 1; var sound : AudioClip; var soundVolume : float = 2.0;

static var Score : int;

private var used = false; private var mover : DroppableMover;

function Start () { // do we exist in the level or are we instantiated by an enemy dying? mover = GetComponent(DroppableMover); }

function ApplyPickup (playerStatus : ThirdPersonStatus) {

 // A switch...case statement may seem overkill for this, but it makes adding new pickup types trivial.
 switch (pickupType)
 {
     case PickupType.Health:
         playerStatus.AddHealth(amount);
         
         break;
         
 
         case PickupType.bamboo:
         playerStatus.AddScore(amount);
         break;
         
         
 }
 
 return true;

}

function OnTriggerEnter (col : Collider) { if(mover && mover.enabled) return; var playerStatus : ThirdPersonStatus = col.GetComponent(ThirdPersonStatus);

 //* Make sure we are running into a player
 //* prevent picking up the trigger twice, because destruction
 //  might be delayed until the animation has finished
 if (used || playerStatus == null)
     return;
 
 if (!ApplyPickup (playerStatus))
     return;

 used = true;
 
 // Play sound
 if (sound)
     AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);
     
 
 
 // If there is an animation attached.
 // Play it.
 if (animation && animation.clip)
 {
     animation.Play();
     Destroy(gameObject, animation.clip.length);
 }
 else
 {
     Destroy(gameObject);
 }

}

// Auto setup the pickup function Reset () { if (collider == null)
gameObject.AddComponent(BoxCollider); collider.isTrigger = true; }

@script RequireComponent(SphereCollider) @script AddComponentMenu("Third Person Props/Pickup")

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by YikYikHeiHei · Aug 20, 2011 at 09:39 AM

What are you want to use? I see you have use the GUI.Label and guiText.text.

If you want to use GUI.Label, you should to use

 GUI.Label(Rect(10, 10, 100, 20), text + Score.ToString());

And is you want to use guiText.text, you should use

 guiText.text = text + Score.ToString();
Comment
Add comment · Show 2 · 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 kiko · Aug 20, 2011 at 06:20 PM 0
Share

thx i try to change alrdy i usin guitext..btw i realize the OnTriggerEnter doesn't seen to wrk in my gui text...wat is reali the cause of tis prob..

avatar image YikYikHeiHei · Aug 20, 2011 at 11:46 PM 0
Share

Are you turned on the Is Trigger in your collider?

avatar image
0

Answer by sdfwefwedfgherhr · Aug 20, 2011 at 01:52 PM

ONLINE STORE:

====( http://popbuynow.com/ )=====

The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time.

Air jordan(1-24)shoes $30

Handbags(Coach l v f e n d i d&g) $35

Tshirts (Polo ,ed hardy,lacoste) $15

Jean(True Religion,ed hardy,coogi) $30

Sunglasses(Oakey,coach,gucci,A r m a i n i) $15

New era cap $12

Bikini (Ed hardy,polo) $20

accept paypal and free shipping

====( http://popbuynow.com/ )=====

====( http://popbuynow.com/ )=====

====( http://popbuynow.com/ )=====

====( http://popbuynow.com/ )=====

====( http://popbuynow.com/ )=====

====( http://popbuynow.com/ )=====

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Save variable value. 1 Answer

Using images to show numbers 1 Answer

Highscore Save 0 Answers

Scoreboard will not update 1 Answer

Don't destroy script on load 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