private void OnCollisionEnter(Collision collision) { TargetP1 target = collision.gameObject.GetComponent <TargetP1>(); if (target != null && target.color == /*my*/ color) { Destroy(collision.gameObject); } Destroy(gameObject); }
private void SpawnNextTarget() { //TargetP1 nextTarget = Random.Range(0, 2) == 0 ? redTarget : yellowTarget; TargetP1 nextTarget = null; if (Random.Range(0, 2) == 0) { nextTarget = redTarget; } else { nextTarget = yellowTarget; } Instantiate <TargetP1>(nextTarget, transform.position, transform.rotation) // Instantiate target .TargetRigidbody // Access to target RB .AddForce(transform.forward * shootForce, ForceMode.Impulse); // add force to target RB }