Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Delete clone object if a new one spawnes

$
0
0
Hi. How can I delete this bullet GameObject if a new one is spawned? There should always just be one in the scene. I tried doing something here, but I ended up deleting my whole character... using UnityEngine; using System.Collections; public class Shooter : MonoBehaviour { public GameObject bullet = null; public float bulletSpeed = 500f; public Transform target; public float MoveTowardsSpeed; public bool HookActive = false; private void Update () { if (Input.GetButtonDown ("Fire1")) { if (HookActive == true) { GameObject.Destroy (bullet); HookActive = false; } HookActive = true; GameObject shot = GameObject.Instantiate (bullet, transform.position + (transform.forward * 2), transform.rotation) as GameObject; shot.GetComponent().AddForce (transform.forward * bulletSpeed); float step = MoveTowardsSpeed * Time.deltaTime; transform.position = Vector3.MoveTowards (transform.position, target.position, step); } } }

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>