Question by
Box_Frog · Sep 16, 2020 at 07:55 PM ·
3dtransparency
When I change the Alpha Cutoff in my material it doesn't change the object?
I'm trying to make it so the player becomes transparent at a certain camera angle. And I had this working code working before and I was trying to Animate it so the transition between transparent and visible looked smoother but when I tried to make the object transparent by moving the slider my object wouldn't change so I tried playing around with my code to try and fix it and now the player doesn't become transparent at all. Here's the code I'm using:
public class PlayerOpacity : MonoBehaviour
{
public CinemachineFreeLook camY;
public Material material;
public float alphaLevel = 0f;
// Update is called once per frame
void Update()
{
if (camY.m_YAxis.Value < .2)
{
FindObjectOfType<GameManager>().hidePlayer();
} else
{
FindObjectOfType<GameManager>().unhidePlayer();
}
material.SetFloat("_Cutoff", alphaLevel);
}
}
public class GameManager : MonoBehaviour
{
bool playerIsHidden = false;
bool playerIsShowing = false;
public void hidePlayer()
{
if (playerIsHidden == false)
{
Debug.Log("Hide Player");
playerIsHidden = true;
playerIsShowing = false;
var class1 = GameObject.Find("GFX").GetComponent<PlayerOpacity>();
class1.alphaLevel += 1f;
}
}
public void unhidePlayer()
{
if (playerIsShowing == false)
{
Debug.Log("Unhide Player");
playerIsShowing = true;
playerIsHidden = false;
var class1 = GameObject.Find("GFX").GetComponent<PlayerOpacity>();
class1.alphaLevel -= 1f;
}
}
}
Comment
Your answer