Hi guys,
I’m working on a arrow type projectile, everything is fine but the projectile doesn’t become child to the object that hit.
Can someone tell me what i’m doing wrong? Thanks
Arrow.cs
using System.Collections;
public class Arrow : MonoBehaviour
{
public GameObject StickyProjectile;
public GameObject hitEffect;
public float Damage;
void OnHit()
{
Quaternion randomRotation = Quaternion.Euler(0f, 0f, Random.Range(0f, 360f));
Instantiate(hitEffect, transform.position, randomRotation);
Instantiate(StickyProjectile, transform.position, transform.rotation);
Destroy (gameObject);
}
void OnTriggerEnter2D (Collider2D col)
{
//on collision this gameObject will become a child of the collided object before destroying it
transform.parent = col.transform;
if(col.tag == "Enemy")
{
col.gameObject.GetComponent<EnemyHp>().HP -= Damage;
OnHit();
Destroy(gameObject);
}
else if(col.gameObject.tag == "Breakable")
{
col.gameObject.GetComponent<BreakablePropScript>().PropHp -= Damage;
OnHit();
Destroy(gameObject);
}
else if(col.gameObject.tag != "Player")
{
OnHit();
Destroy(gameObject);
}
}
}