Script to get Eye Material to move only seems to work in Inspector/Edit Mode
I'm trying to make my a Pupil Texture (which is on "Eye Material") move in correlation with an Eye Bone's rotation.
What's weird is that the script I have actually *does* make the Eye Material move-- in the Inspector!-- but not visually move in the actual game.
Does anyone have suggestions about how to make the EyeMat actually successfully move with the EyeBone rotation?
Gif of Eye bone transforms changing:
https://i.stack.imgur.com/v7TBG.gif
Gif of Eye material transforms changing:
https://i.stack.imgur.com/WhCj0.gif
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EyeBoneMatOffset : MonoBehaviour
{
public Transform targetBone;
public Material mat;
public float offsetMultiplier = 0.05f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Create a vector to offset the material
var offset = new Vector2(targetBone.transform.localRotation.eulerAngles.x * offsetMultiplier,
targetBone.transform.localRotation.eulerAngles.y * offsetMultiplier);
//Apply the offset
mat.mainTextureOffset = offset;
}
}
Your answer
Follow this Question
Related Questions
Need help for bullet script,Script for bullet 0 Answers
Make enemy patrol without Nav Points? 0 Answers
Flashlight flickering script? 0 Answers
Rigidbody2D movement is lagging 0 Answers
Button appears when switching between scenes or quitting game 1 Answer