public void gunShot() { timer = effectDelay; enableEffects(); gunLine.SetPosition(0, transform.position); Ray shot = new Ray(); RaycastHit rayInfo; shot.origin = transform.position; shot.direction = transform.forward; Debug.Log("Gunshot"); if (Physics.Raycast(shot, out rayInfo, maxDistance)) { EnemyController target = rayInfo.collider.GetComponent <EnemyController>(); if (target != null) { target.takeDamage(); } else if (rayInfo.collider.tag == "Button") { ResetButton button1 = rayInfo.collider.GetComponent <ResetButton>(); if (button1 != null) { button1.OnClick(); } else { KeyboardButton key = rayInfo.collider.GetComponent <KeyboardButton>(); if (key != null) { key.OnClick(); } } } gunLine.SetPosition(1, rayInfo.point); } else { gunLine.SetPosition(1, shot.origin + shot.direction * maxDistance); } }