TargetCombine.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Making the gameobject with 'tagName' as a target, so that it can be shown in the map
  3. *
  4. * Author: Jingyi Jia
  5. *
  6. */
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using UnityEngine;
  10. // add Target
  11. namespace RadarComponents
  12. {
  13. public class TargetCombine : MonoBehaviour
  14. {
  15. public string tagName;
  16. public GameObject originObj;
  17. GameObject[] targets;
  18. private void Awake()
  19. {
  20. }
  21. // Start is called before the first frame update
  22. void Start()
  23. {
  24. }
  25. // Update is called once per frame
  26. void Update()
  27. {
  28. if (tagName != null) {
  29. targets = GameObject.FindGameObjectsWithTag(tagName);
  30. if (targets.Length != 0)
  31. {
  32. AddTargets();
  33. this.enabled = false;
  34. }
  35. }
  36. }
  37. private void AddTargets(){
  38. foreach (GameObject targetObj in targets)
  39. {
  40. GameObject target = GameObject.Instantiate(originObj, new Vector3(0, 0, 0), Quaternion.identity, targetObj.transform);
  41. target.transform.localPosition = new Vector3(0, 0, 0);
  42. target.SetActive(true);
  43. }
  44. }
  45. }
  46. }