Well lets say this script is attached to a box, that box is a child of my Enemy and has a box collider and a kinematic rigidbody because if not it mess up. Im trying to do that when this object collides with player charactercontroller the Player gets damaged.
Here is what i tryed. Raycasting works but is not what im looking for, I also tryed OnCollisionEnter butdidnt worked.And i dont know if im using OnControllerColliderHit correctly. So can you give me any solution? Please!!
var attack = 30;
var canattack = 1;
var cooldown : double = 2.2;
var distance : double = 0.5;
//function Update() {
// if(Enemy.GetComponent(EnemyAI).attackEnabled == 0) {
// var fwd = transform.TransformDirection (Vector3.forward);
// var hit : RaycastHit;
// if(canattack == 1) {
// if (Physics.Raycast (transform.position, fwd, hit, distance)) {
// if (hit.collider.gameObject.tag == "Player") {
// hit.collider.gameObject.GetComponent(PlayerHealth).damage += attack;
// print ("Ouch!That Hurts");
// canattack = 0;
// Attack();
// }
// }
// }
//}
//function Attack() {
// while(true) {
// if(canattack == 0) {
// yield WaitForSeconds(cooldown);
// canattack = 1;
// }
// else {
// yield;
// }
// }
//}
//function OnCollisionEnter(collision : Collision) {
// print ("Collide!");
// if (collision.gameObject.tag == "Player") {
// collision.gameObject.GetComponent(PlayerHealth).damage += attack;
// print ("Ouch!");
// }
//}
//function OnControllerColliderHit (hit : ControllerColliderHit) {
// if (hit.collider.tag == "Player") {
// hit.collider.GetComponent(PlayerHealth).damage += attack;
// print ("Ouch!");
// }
//}