i am having problem to get this done i dont know how to make a mesh with a texture in 2d to face the player from different angles like in Doom the game, for this moment iahve this code and a mesh filter and a meshrenderer could you please help me?
public class Enemy : Entity
{
Transform player;
public float angle;
Vector3 direction;
public MeshRenderer spriteObj;
public Texture[] mat;
Texture F = Resources.Load<Texture>("Sprites/F") as Texture;
Texture FR = Resources.Load<Texture>("Sprites/FR") as Texture;
Texture R = Resources.Load<Texture>("Sprites/R") as Texture;
Texture BR = Resources.Load<Texture>("Sprites/BR") as Texture;
Texture B = Resources.Load<Texture>("Sprites/B") as Texture;
Texture FL = Resources.Load<Texture>("Sprites/FL") as Texture;
Texture L = Resources.Load<Texture>("Sprites/L") as Texture;
Texture BL = Resources.Load<Texture>("Sprites/BL") as Texture;
// Use this for initialization
public Enemy() : base("Enemy")
{
player = GameObject.FindWithTag("Player").transform;
mat = new Texture[8] { F, FR, R, BR, B, BL, L, FL};
}
// Update is called once per frame
override public void Update()
{
direction = player.transform.position - skin.transform.position;
angle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
ChangeDirection();
}
void ChangeDirection()
{
if (angle < 0) angle += 360; // Just in case
skin.GetComponent<MeshRenderer>().material.mainTexture = mat[Mathf.FloorToInt(angle / 360f * mat.Length) % mat.Length];
}
}