05-25-2023, 10:05 PM
(05-25-2023, 09:45 AM)_Aka_ Wrote: HiI wrote the following script to try to control the value, but I seem to be getting an error saying that MissingComponentException, there is no Meshrender attached to the Game Object.
All the material parameters are internally stored in an array. It seems that the animator does not show members of type Array.
The solution would be then to create a script that will act as a middle man between the animation and the module:
The script will for example have a float V offset value, editable by an animation. The script will every frame apply that value to yourModule.MaterialSettings[yourMaterialIndex].UVOffset.y
Did this help?
Code:
using UnityEngine;
public class MaterialOffsetController : MonoBehaviour
{
public float vOffset;
public GameObject river;
public int materialIndex;
private MeshRenderer meshRenderer;
private void Start()
{
// Get the MeshRenderer component from the specified GameObject
meshRenderer = river.GetComponent<MeshRenderer>();
}
private void Update()
{
// Update the material's UVOffset.y value based on the vOffset value
Material[] materials = meshRenderer.materials;
if (materialIndex >= 0 && materialIndex < materials.Length)
{
Material material = materials[materialIndex];
Vector2 offset = material.GetTextureOffset("_MainTex");
offset.y = vOffset;
material.SetTextureOffset("_MainTex", offset);
}
}
}
I am setting the script on a empty parent game object and selecting the Curvy Spline Generator as the GameObject. I am pretty sure I am not access the property value correctly.