Tinting Layer of Layered Character
I created a basic code to change the color of my characters eyes. It changes based of a variable to different colors. However, it doesn't update unless I rollback and sometimes the colors aren't correct or even changed.
My current set up is this. In Unity on the layered character I have attached the script as a component to the eyes themselves. When the game runs there is no change to the color of the eyes. The game uses the default color set in UNity. However, when the character is called. It logs that the eyes have changed to the appropriate value. When I roll-back the eyes update, but are either white or a bright yellow. No where near the colors I choose in the script and far from it.
This is not what I want. I want the eyes to change colors when I call my other function UpdateTemperment. When I tried to add it there, I got an error saying "Assets\Scripts\CScripts\Check.cs(56,9): error CS0120: An object reference is required for the non-static field, method, or property 'EyeColor.UpdateEyes()'" No idea how to fix that.
So I just went with a Start() temporarily. It doesn't change the eye color unless you roll back and even then the colors are not correct....How would I remedy this?
Am I doing this properly?
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Naninovel;
[Naninovel.ExpressionFunctions]
public class EyeColor : MonoBehaviour
{
SpriteRenderer m_SpriteRenderer;
// Start is called before the first frame update
void Start()
{
var variableManager = Engine.GetService<ICustomVariableManager>();
string active_temper = variableManager.GetVariableValue("temper");
if (active_temper == "brash")
{
// Dark Blue Eyes
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_SpriteRenderer.color = new Color(34,96,169,255);
}
else if (active_temper == "shy")
{
//Green brown eyes.
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_SpriteRenderer.color = new Color(59,78,0,255);
}
else
{
//Teal blue eyes.
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_SpriteRenderer.color = new Color(35,156,167,255);
}
Debug.Log("From Start() I updated the eyes to " + active_temper);
}
void UpdateEyes()
{
var variableManager = Engine.GetService<ICustomVariableManager>();
string active_temper = variableManager.GetVariableValue("temper");
if (active_temper == "brash")
{
// Dark Blue Eyes
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_SpriteRenderer.color = new Color(34,96,169,255);
}
else if (active_temper == "shy")
{
//Green brown eyes.
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_SpriteRenderer.color = new Color(59,78,0,255);
}
else
{
//Teal blue eyes.
m_SpriteRenderer = GetComponent<SpriteRenderer>();
m_SpriteRenderer.color = new Color(35,156,167,255);
}
Debug.Log("From UpdateEyes: The eyes are " + active_temper);
}
}