- Home /
Question by
FabriBertani · Jul 08, 2016 at 12:22 PM ·
c#collisioncolliderenemyfirst-person
Fist Punch Collision
Hi everyone, i'm making a first person boxing game that is a player against an enemy. So i've got a first person controller, then i add two arms with front punch animation (left arm and right arm) and then i attached to the fists an sphere collider to get when it hits the enemy collider. The problem is when i play the animation on mousedown the sphere collider doesn't move and the fists overstep the enemy collider and don't activate the collider.
What can i do to detect the hit? This is part of my code for e.g:
using UnityEngine;
using System.Collections;
public class RightPunchScript : MonoBehaviour {
public GameObject Enemy;
private Animation anim;
void Start(){
anim = GetComponent<Animation> ();
}
public void OnCollisionEnter (Collider other){
if (other.gameObject.tag == "Enemy"){
Debug.Log ("I hit the Enemy!");
Enemy.GetComponent<EnemyScript> ().EnemyDamage ();
}
}
void Update(){
if (Input.GetMouseButtonDown(1)){
anim.Play("RightPunch");
}
}
}
Comment