- Home /
Question by
hackgamn · Jan 03, 2014 at 03:47 AM ·
collisioncharacteroncollisionenter
Problems with sword's and character's colliders
Hi, I am making my first game and I do not really understand the collisions. I was trying to detect a collision between my character(charactercontroller) and the enemy's sword(rigidbody, mesh collider), using oncontrollercolliderhit, but it did not work. Could anyone help me?
The character's script using UnityEngine; using System.Collections;
public class PlayerStats : MonoBehaviour {
//public int LVL;
//public GameObject Target;
public int MaxHealth; // Максимальное количество здоровья
public int CurHealth; // Текущее количество здоровья
public int MaxMana; // Максимально количество маны
public int CurMana; // Текущее количество маны
public bool AttackStats = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(MaxHealth < CurHealth) CurHealth = MaxHealth;
if(MaxMana < CurMana) CurMana = MaxMana;
if(CurHealth < 0) CurHealth = 0;
}
void OnCollisionEnter(Collision playerCollider){
if(playerCollider.gameObject.tag == "sword"){
Debug.Log("Hit Player");
}
}
}
First I had Oncontrollercolliderhit, then I changed it to oncollisionEnter, but it still doesnt work. Help, please!
Comment
Your answer
Follow this Question
Related Questions
Terrain, Player falls through.... but only some parts. 0 Answers
collision detection not working? 1 Answer
Collision issue with SetParent (C#) 1 Answer
Collision doesn't work 1 Answer
OnCollisionEnter for other object? 2 Answers