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 Derek 1 · Apr 10, 2011 at 11:30 PM · scorelerpz3dplatformtutorial

Score system help

I am trying to add a scoring system to the Lerpz Escapes game. I have tried doing a few things but no matter what I change, its not working. Still learning javascript as well. For those of you that have done the Lerpz guide, I have added scoring to the Pickup script.

Pickup Script:

enum PickupType { Health = 0, FuelCell = 1 } var pickupType = PickupType.FuelCell; var amount = 1; var sound : AudioClip; var soundVolume : float = 2.0; static var myScore : int = 0;

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

function Start () { mover = GetComponent(DroppableMover); }

function ApplyPickup (playerStatus : ThirdPersonStatus) { switch (pickupType) { case PickupType.Health: playerStatus.AddHealth(amount); break;

     case PickupType.FuelCell:
         playerStatus.FoundItem(amount);
         break;

 }

 return true;

}

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

 if (used || playerStatus == null)
     return;

 if (!ApplyPickup (playerStatus))
     return;

 used = true;

 myScore += 1;

 if (sound)
     AudioSource.PlayClipAtPoint(sound, transform.position, soundVolume);

 if (animation && animation.clip)
 {
     animation.Play();
     Destroy(gameObject, animation.clip.length);
 }
 else
 {
     Destroy(gameObject);
 }

}

function Reset () { if (collider == null)
gameObject.AddComponent(BoxCollider); collider.isTrigger = true; }

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

Then I created another script called Scoring and it looks like this:

@script RequireComponent(GUIText)

var myScore : float = 0;

function Update () { guiText.text = "Score : " +myScore; transform.position.x = .15; transform.position.y = .91; }

So, when I load the game, I see the word "Score : 0" but whenever I pickup an item, the score does not change. So, I think something is wrong with the Pickup script that I updated. My goal is to make it so when you pickup a FuelCell you get 5 points and the hearts you get 10 points, but first I just want to get it working. Again, I am still learning javascript, so please provide as many details as possible. Thanks for the help!

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 Parthon · Apr 11, 2011 at 12:18 AM

The myScore in the pickup and the myScore in the Scoring script are not linked in any way.

In the pickup script you need to increase the points in the scoring script by using GetComponent()

How to link it up depends on how your objects and scripts are arranged.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

3D Platform Tutorial Camera Problem 1 Answer

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

Why does Lerpz flap his arms in the 3D Platformer tutorial? 0 Answers

Unity Game Score Script 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