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 tahamtan · Mar 21, 2011 at 06:38 PM · playerscorecollidelive

live system for sword

Hi, I used this script on player character

void OnControllerColliderHit(ControllerColliderHit hit) 
{
if(hit.collider.tag=="sword_enemy")
    {
        col="hit";
        live--;
    }
}

but after collide , live shows -189 or more, this result is for one collide not more, how can i fixed it? one collide and one live--

i tried by OnTriggerEnter,too and that result was wrong

this is my complete code

using UnityEngine; using System.Collections;

public class playerCollid : MonoBehaviour { public string col=""; public int live=5; // Use this for initialization void Start () {

 }

 // Update is called once per frame
 void Update () {

 }

 void OnControllerColliderHit(ControllerColliderHit hit) 
 {
 if(hit.collider.tag=="sword_enemy")
     {
         col="hit";
         live--;
     }
 }
 void OnGUI()
 {
     GUI.Label(new Rect(2,2,100,100),live.ToString());
 }
 /*
 void OnTriggerEnter(Collider other) 
 {
     if(other.tag=="sword_enemy")
     {
         print("trigger");
     }

 }
 */

}

Comment
Add comment · Show 5
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 DaveA · Mar 21, 2011 at 07:08 PM 0
Share

What was the result with OnCollisionEnter() ? Because I would think that is a better event to handle here.

avatar image tahamtan · Mar 21, 2011 at 08:33 PM 0
Share

I used the character controller for the player so I think i've to use the OnControllerColliderHit(ControllerColliderHit hit) , but i tried with OnCollisionEnter() too, but its didnt show any collide with this method, i dont no why? by the way thanks so much DaveA

avatar image DaveA · Mar 21, 2011 at 09:51 PM 0
Share

I'm guessing that OnControllerColliderHit() is getting called (much) more than once per frame. If using OnCollisionEnter, did you set the .isTrigger = true on the character controller?

avatar image tahamtan · Mar 21, 2011 at 10:37 PM 0
Share

I added .isTrigger=true on the character controller, but doesn't work yet, I think the OnCollisionEnter just work on rigidbody , I added a cube as a sword and attached the script on it(for test), but doesnt work when character touch it, thanks DaveA

avatar image tahamtan · Mar 21, 2011 at 10:44 PM 0
Share

OnCollisionEnter is the best method for me but it works just between two rigidbody collide to another(i tested it), but how can I use OnCollisionEnter for character controller and a cube?( i can not use rigidbody for character or for cube)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Myth · Mar 21, 2011 at 09:36 PM

Test for a hit as you have,

then test if it is the first hit,

if so apply damage,

if not ignore,

if no hit then reset the var you use to check if it is the first hit.

good luck with whatever method you end up using!

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

Score Question Java Script, problem 1 Answer

Switching Player 1 Answer

Organising player Score from highest to lowest? 2 Answers

When Colliding With Animation, Player Re-spawns And Keeps Moving. 1 Answer

How to make player (sphere) shoot the ball (another sphere)? 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