- Home /
Question by
el-mas-pro-470 · Jan 29, 2019 at 05:45 PM ·
targetaimingautomaticautomaticallythird-person-shooter
How to assign auto target with tag in range?Help!
Hello! I ask you something, how do I assign to the variable "Target" each object with a tag in a shooting range? Thank you!
using UnityEngine;
using System.Collections;
public class LookTarget : MonoBehaviour {
public Transform target;
void Update()
{
// Rotate the camera every frame so it keeps looking at the target
transform.LookAt(target);
}
}
Comment
Best Answer
Answer by sirjoan620 · Jan 29, 2019 at 07:15 PM
First of all you should edit target as array:
public Transform[] target;
Then you should find all the GameObjects with GameObject.FindGameObjectsWithTag. Check the distances of these objects then add to your target variable.
Your answer
Follow this Question
Related Questions
Automatic accceleration 1 Answer
Turrets |Aiming don't work 1 Answer
Make the turret automatically rotate to look at where the crosshair is aimed at. 3 Answers
Look at target and flip 1 Answer
Bone lookat do not work Help! 1 Answer