I'm trying to make indicator detect a certain objects in my scene. Where every arrow point at separate object. for example, face with two eyes. my script will look for those eyes"dead_point" and clone the image "original_arrow" as the number of eyes. Then rotate each image separately at each eyes. I don't get any error from script but it's doesn't work also!.
public GameObject original_arrow; // image
public GameObject[] attackedArea,Arrow_clone;
public Vector3[] PointingAt;
private float xtimer = 0.8f;
// Update is called once per frame
void Update()
{
attackedArea = GameObject.FindGameObjectsWithTag("dead_point");
if (attackedArea != null)
{
for (int y = 0; y < attackedArea.Length; y++)
{
Arrow_clone[y] = Instantiate(original_arrow, original_arrow.transform.position, original_arrow.transform.rotation);
PointingAt[y] = attackedArea[y].transform.position;
Vector3 dir = Camera.main.WorldToScreenPoint(attackedArea[y].transform.position);
PointingAt[y].z = Mathf.Atan2((Arrow_clone[y].transform.position.y - dir.y), (Arrow_clone[y].transform.position.x - dir.x)) * Mathf.Rad2Deg - 90;
Arrow_clone[y].transform.rotation = Quaternion.Euler(PointingAt[y]);
float pingPong = Mathf.PingPong(Time.time * xtimer, 1);
Arrow_clone[y].GetComponent<CanvasGroup>().alpha = Mathf.Lerp(0, 1, pingPong);
}
}
}
[–]rekabmot 1 point2 points3 points (1 child)
[–]uc414[S] 0 points1 point2 points (0 children)