Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Flagster · Jan 25, 2016 at 07:23 PM · collisiondetection

Collision not working

Ok, so i got the code right here :

 using UnityEngine;
 using System.Collections;
 
 public class RogueSheet : MonoBehaviour {
 
     public int Level = 1;
     public int Exp = 0;
     public int ReqExp;
     public float MaxHealth = 100;
     public float Health = 100;
     public float Mana;
     public float Str = 10;
     public float Stam = 8;
     public float Int = 5 ;
     public float Luck = 12;
     public double DamageRed;
     public double CritRate;
     public int CritDmg = 200;
     public double Damage;
 
 
     // Use this for initialization
     void Start () {
         print(Health);
     }
     
     // Update is called once per frame
     void Update () {
 
         ReqExp = Level * 100;
         MaxHealth = 92 + Stam;
         DamageRed = Stam * 0.3;
         CritRate = Luck * 0.3;
         Damage = 10 + (Str / 2);
         Mana = 20 + Int;
         if (Stam > 8)
             Health = MaxHealth;
     }
     void OnCollisionEnter(Collision _collision)
     {
         if (_collision.collider.gameObject.tag == "Enemy")
         {
             print("HIT!!!!!!!!!");
         }
     }
 }

The problem is it wont check for colision, i tryied removing the stats and let just the collision script and still nothing. I can confirm that the enemy its on "Enemy" tag and that it isnt kinematic. Also both bodies have rigidbody attached to them. Any help ?

Also, i tryied both

   if (_collision.collider.gameObject.tag == "Enemy")

and

 if (_collision.gameObject.tag == "Enemy")


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 ShadyProductions · Jan 25, 2016 at 07:48 PM

Do they have colliders?
Also change this line:

 if (_collision.gameObject.tag == "Enemy")
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 Danisuper · Jan 26, 2016 at 12:07 PM

Is your game 2D or 3D? If it's 2D you must use OnCollisionEnter2D(Collision2D collision) and use the 2D colliders

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 vreiche · Jan 26, 2016 at 12:24 PM

So both player and enemy need to have colliders. On the enemy put two colliders, one regular, and another with is Trigger checked. Also, make sure your Enemy has the Enemy tag on it.

Code wise, make sure it's

  if (_collision.gameObject.tag == "Enemy")
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

collision wont work 1 Answer

Collision isn't detected between two obects 1 Answer

Detecting Trigger Collision for Mecanim Animator 0 Answers

Collision detection not working properly with 2D sprites 1 Answer

Need help with collision detection 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