What to do to make my object in the game “log” compatible with my script which causes the flashing of the object ?
this my script:
[SerializeField] private SimpleFlash flashEffect;
private void OnCollisionEnter2D(Collision2D collision)
{
//we don't even want to detect collisions when the knife isn't active
if (!isActive)
return;
//if the knife happens to be active (1st collision), deactivate it
isActive = false;
//collision with a log
if (collision.collider.tag == "Log")
{
flashEffect.Flash();
GetComponent<ParticleSystem>().Play();
bezLOSoundEffect.Play();
//stop the knife
rb.velocity = new Vector2(0, 0);
//this will automatically inherit rotation of the new parent (log)
rb.bodyType = RigidbodyType2D.Kinematic;
transform.SetParent(collision.collider.transform);
//move the collider away from the blade which is stuck in the log
knifeCollider.offset = new Vector2(knifeCollider.offset.x, -0.4f);
knifeCollider.size = new Vector2(knifeCollider.size.x, 1.2f);
//Spawn another knife
GameController.Instance.OnSuccessfulKnifeHit();
}
It is mainly about the line: flashEffect.Flash();
The script is in a different inspector, so it works on the wrong object. I’ve tried these ways, but I always get an error or it just doesn’t work.
flashEffect.Flash(log);
flashEffect.Flash(“log”);
flashEffect.Flash(log.gameObject);
flashEffect.Flash(log.gameObject);