- Home /
This question was
closed Jan 30, 2019 at 11:06 PM by
el-mas-pro-470 for the following reason:
Fixed!!!!
Question by
el-mas-pro-470 · Jan 30, 2019 at 07:17 PM ·
simplearray of gameobjectsautomatickilltargetting
(Updated) How do I make a target system?
Hello, I made a script and updated it, I need to make a system to choose targets within a range, I have the whole system ready but for a single objective that when killing it keeps pointing to it, and clearly is not what I want to do, does anyone Do you know something simple about using the matrix? (That is, an automatic list with all the objectives). Thank you!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerAim : MonoBehaviour {
public Transform CamaraTransform;
public Transform Target;
public bool LookingTarget = false;
public GameObject Camara;
public bool Targeting = false;
public MonoBehaviour SmoothFllw;
public GameObject Crosshair;
public GameObject Player;
public RawImage Imagen;
public float Distancia;
void Start ()
{
}
void Update ()
{
var distance = Vector3.Distance(Target.position, transform.position);
if(LookingTarget == true)
{
CamaraTransform.LookAt(Target);
}
Camara = GameObject.Find ("Camera");
SmoothFllw = Camara.GetComponent("SmoothFollow") as MonoBehaviour;
if(Targeting == true && distance <= Distancia)
{
Vector3 TextoPosicion = Camera.main.WorldToScreenPoint(Target.transform.position);
Imagen.transform.position = TextoPosicion;
SmoothFllw.enabled = false;
LookingTarget = true;
Crosshair.SetActive(true);
Player.gameObject.GetComponent<MouseLook>().enabled = false;
}
if(Targeting == false)
{
LookingTarget = false;
SmoothFllw.enabled = true;
Crosshair.SetActive(false);
Player.gameObject.GetComponent<MouseLook>().enabled = true;
}
if(Input.GetMouseButtonDown(1))
{
Targeting = true;
}
if(Input.GetMouseButtonUp(1))
{
Targeting = false;
}
}
}
Comment
Follow this Question
Related Questions
How do I destroy all the GameObjects in an array? 3 Answers
How to find index of colliding Game Object in OnCollisionEnter2D() 2 Answers
Adding Waypoints using a List 2 Answers
how to check if all object in my array are destroyed (C#) 3 Answers
Instantiating array in GameManager upon loading Scene 0 Answers