using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
public class ChildFollow : MonoBehaviour
{
public float ChildHealth = 5f;
public Transform PlayerBody;
public float ChildSpeed = 4;
// Update is called once per frame
void Update()
{
transform.position = Vector3.MoveTowards(this.transform.position, PlayerBody.position, ChildSpeed * Time.deltaTime);
Vector3 target = PlayerBody.position;
Vector3 destination = PlayerBody.position;
target.y = transform.position.y;
destination.y = transform.position.y;
transform.LookAt(target);
if (ChildHealth <= 0)
{
Destroy(this.gameObject);
}
}
public void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("PlayerSlap"))
{
ChildHealth--;
Debug.Log("Child Touched");
}
}
}
#why is my attacking not working
1 messages · Page 1 of 1 (latest)
basically only check the OnCollision Method
the other code has nothing to do with the issue
bassically i have a gameobject that works as a hit like if clicked the game mesh and collider gets turned on but yeah i have that in another script
but in this script besides the movemnt i want that if the AI touches a gameobject with the Tag PlayerSlap to deduct the health of the child
and if the childs health is smaller or equals to 0 to destory the Prefab
heres the gameobject btw
at u can see the tag is PlayerSlap and the Collider is set to triger
pls help
Out of all the possible debug messages...