I was searching around for a solution to this, and everyone basically said to just put a script on the child. I can’t do this because my script disables the shield object when not blocking. Is there any way to check for a collision in child objects? Here’s my script,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBlock : MonoBehaviour
{
public Animator animator;
public Player player;
public AttackBoy attackBoy;
public bool blockHitter;
private bool blocking;
public GameObject shield;
void Start()
{
attackBoy = GetComponentInParent<AttackBoy>();
animator = GetComponentInParent<Animator>();
player = GetComponentInParent<Player>();
}
void Update()
{
if (Input.GetKey(KeyCode.S))
{
blocking = true;
animator.SetFloat("blockPerc", 0.5f);
}
if (Input.GetKeyUp(KeyCode.S))
{
blocking = false;
if (!attackBoy.attackRoutine)
{
player.stopMove = false;
}
}
if (blocking)
{
player.stopMove = true;
shield.SetActive(true);
}
else
{
shield.SetActive(false);
animator.SetFloat("blockPerc", 0f);
}
}
private void OnTrigger2D(Collider2D collision)
{
if (collision.CompareTag("Enemy") || collision.CompareTag("AttackTrigger") && !blockHitter)
{
StartCoroutine(BlockHit());
}
}
IEnumerator BlockHit()
{
blockHitter = true;
yield return new WaitForSeconds(0.2f);
animator.SetFloat("blockPerc", 1f);
yield return new WaitForSeconds(1);
blockHitter = false;
}
}
I’m trying to make a shield, if anyone’s got any better suggestions I’m game, I cooked this up myself so it might not be optimal haha.
Thanks in advance