Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Unity C# The following code implements several functions: Two tanks can shoot at each other and will destroy each other (but cannot respawn) Requirements: When

Unity C#

The following code implements several functions: Two tanks can shoot at each other and will destroy each other (but cannot respawn)

Requirements: When any tank is destroyed by the opponent's bullet, it will respawn at the default location after a few seconds delay. (Unlimited rebirth)

code

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Bullet : MonoBehaviour

{

GameObject tank1;

GameObject tank2;

public int bullet;

// Start is called before the first frame update

void Awake()

{

tank1 = GameObject.Find("Tank1");

tank2 = GameObject.Find("Tank2");

}

void OnTriggerEnter2D(Collider2D other)

{

if (bullet == 1)

{

if (other.tag == "Wall")

{

Destroy(this.gameObject);

}

if (other.tag == "Tank2")

{

Destroy(this.gameObject);

Destroy(other.gameObject);

//tank2 = Instantiate(tank2, transform.position, transform.rotation);

}

}

else if (bullet == 2)

{

if (other.tag == "Wall")

{

Destroy(this.gameObject);

}

if (other.tag == "Tank1")

{

Destroy(this.gameObject);

Destroy(other.gameObject);

//tank1 = Instantiate(tank1, transform.position, transform.rotation);

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

Sidestep common tone and grammar problems

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago

Question

=+3 In what ways can an MNE improve or change its approach to IHRM?

Answered: 1 week ago