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 Kyle 11 · Apr 11, 2011 at 12:38 PM · javascriptcollisioncharactercontrollerdamagehealth

Character controller mess up damage

ok well i got a damage and health script to run between two cubes hitting each other, this was a test for a simple player health script. When i added this script to anything with a character controller it suddenly stopped working and in fact, was even detecting that there was a collision between the two objects. I was hoping someone on here could help me find a solution to this problem as it's been bugging me for a while now.

heres the health script

var healthMax = 100; var curHealth = 100; var dieHealth = 0.0;

function ApplyDamage (damage : float) {

 curHealth -= damage;
 print (curHealth);
 if(curHealth <= dieHealth) {
     die();
 }

}

function die () {

Destroy(gameObject);

}

and heres the damage script

var damage = 10;

function OnCollisionEnter (col : Collision) {

col.gameObject.SendMessageUpwards("ApplyDamage", damage); print (damage); Debug.Log ("Hello");

}

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AngryOldMan · Apr 11, 2011 at 12:49 PM

Why don't you put both scripts together? Then you don't have need for the send message function. Also maybe try explicit coding (i believe that's the term if not please someone correct me) in which you state what each variable is, ie. float, int, boolean etc. Here I've cleaned up your code, complied it into one script and added some suitable debug logs, try using that and seeing what errors and logs you get.

var healthMax : int = 100; var curHealth : int = 100; var dieHealth : int = 0.0; var damage : int = 10;

function ApplyDamage (damage : float) { Debug.Log ("Apply Damage"); curHealth -= damage; print (curHealth); if(curHealth <= dieHealth) { Debug.Log ("called die function"); die(); } }

function die () { Destroy(gameObject); Debug.Log ("died"); }

function OnCollisionEnter (collision : Collision) { ApplyDamage(); Debug.Log ("Collision entered"); }

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 Kyle 11 · Apr 11, 2011 at 12:58 PM 0
Share

thank you, i'll give this a try and let you know later.

avatar image
0

Answer by Kyle 11 · Apr 12, 2011 at 11:33 AM

Assets/All Scripts/Player Health.js(27,15): BCE0017: The best overload for the method 'Player Health.ApplyDamage(float)' is not compatible with the argument list '()'.

this is the error that the scripts giving me.

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

Answer by Ves · Apr 29, 2011 at 06:41 PM

Basically it's saying that the function ApplyDamage that you've defined requires an argument (i.e. a float value which represents damage). Your OnCollisionEnter function calls ApplyDamage, but does not pass it an argument, which is required.

The last function in the above script should be:

function OnCollisionEnter (collision : Collision) 
{
   ApplyDamage(damage);
   Debug.Log ("Collision entered");
}

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

Player take damage on collision with AI 1 Answer

For loop on collision (two hit kill) 2 Answers

How to cause damage on collision? 1 Answer

Collision Detection in Capsule Collider 0 Answers

How to Detect Collision, Calculate Velocity+Mass, Apply Damage 0 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