- Home /
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")
Answer by ShadyProductions · Jan 25, 2016 at 07:48 PM
Do they have colliders?
Also change this line:
if (_collision.gameObject.tag == "Enemy")
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
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")
Your answer
Follow this Question
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