Hello All
I have a stationary plane that faces the player
As the player moves around it (360 Degrees) I need the texture to change.
So it’s as if I had taken 16 pictures around an object, the texture would change relative to the players position and it would seem like a 360 “object”
Here is the C# code.
Rotations are working
Quaternions are moving
I just can’t track the numbers correctly to use if statements to control the texture switching.
using UnityEngine;
using System.Collections;
public class LookAt : MonoBehaviour {
public Transform player;
// Here are the 16 textures I manually assign:
public Texture Texture1;
public Texture Texture2;
public Texture Texture3;
public Texture Texture4;
public Texture Texture5;
public Texture Texture6;
public Texture Texture7;
public Texture Texture8;
public Texture Texture9;
public Texture Texture10;
public Texture Texture11;
public Texture Texture12;
// etc etc
void Start()
{
player = GameObject.Find ("Player").transform;
}
void Update()
{
// Plane faces the Player
Vector3 v3 = player.position - transform.position;
v3.y = 0.0f;
transform.rotation = Quaternion.LookRotation(-v3);
// Sending the transform.rotation to the console in hopes of finding something I could use...
Debug.Log (transform.rotation);
// Calls the method fot changing texture.
ChangeTexture();
}
void ChangeTexture()
// What I want to do is every 20 degrees switch the texture
// if the plane is rotated 0 - 20 deg use texture 1
// if the plane is rotated 20 - 40 deg use texture 2 etc
{
if (transform.rotation.y != 0) {
GetComponent<Renderer>().material.mainTexture = Texture2;
}
}
}
I appreciate your looking !
~be