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 /
This question was closed Apr 11, 2014 at 04:09 AM by getyour411 for the following reason:

Duplicate Question

avatar image
0
Question by Modeler71 · Apr 11, 2014 at 03:42 AM · scorehealth

Calling Enemy Health Adding to Player Score

I have one problem lately I cannot figure out, and though there are many of the same questions as to calling other scripts, nothing seems to fit my particular situation. I have these two scripts, and I am trying to get either one to call the other and add to the player score when the enemy is hit. Can someone help me here?

enemyHealth script

var enemyHealth = 5.0; var destroyedParticles : Transform;

function Start () {

}

function Update () {

if(enemyHealth == 0.0) {

Instantiate(destroyedParticles, transform.position, transform.rotation);

Destroy(gameObject); } } function OnGUI (){

GUI.Box(Rect(10, 50, 135, 25),"Enemy 1 Health: " + enemyHealth);

}

function OnCollisionEnter(projectileCollision : Collision) { if(projectileCollision.transform.name == ("PlasmaBall(Clone)")) { enemyHealth -=1; }

}

playerScore script;

var guiScore : GUIText; private var score : int = 0;

function Start () { guiScore.text = "Score: 0"; }

function Update () {

} function OnCollisionEnter(projectileCollision : Collision){ if(projectileCollision.transform.name == ("PlasmaBall(Clone)")){

 score += 10;
 guiScore.text = "Score: " + score;
 }
     

if(score == 3000){ Application.LoadLevel("3PS_scn2"); }

}

???

Comment
Add comment · Show 2
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 Modeler71 · Apr 11, 2014 at 03:31 AM 0
Share

I'm trying to have an empty GameObject in each level with the playerScore script on it that can sense the collisions or if the enemy is destroyed and updates the player's score basically, is what I'm trying to do. Any help would be greatly appreciated. I've had to really work to even get to this point.

avatar image getyour411 · Apr 11, 2014 at 04:09 AM 0
Share

Please format your code when posting questions.

http://unitygems.com/script-interaction-tutorial-getcomponent-unityscript/

There are thousands of examples on using Getcomponent to access variables on Script B from Script A; please review.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Checking for a value overtime 2 Answers

GUI text not updateing 1 Answer

Creating a Lifebar with simple GUI in C# 3 Answers

How to add score/health ? 2 Answers

Using images to show numbers 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