- Home /
Changes(made by a script) to my Image are not visible in either the Gameview or the Scene View, but are visible in the Inspector.
Hey, I was making a little script that makes a image have a hardbeat effect, or at least that was the plan. Beyond that there are probably a million better ways to this, the script does work becouse the outline of this image grows en than shrinks.(In the Inspector)
The problem is that I can't see this happening in eather the Gameview or the Sceneview. But if I spam the activation toggle button, the image does update...
Does someone no what I am doing wrong?
This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HeartbeatEffect : MonoBehaviour
{
[Range(0, 1)]
public float SmallSate = 0.8f;
[Range(0, 1)]
public float LargeState = 0.45f;
[Range(0.05f, 5)]
public float AnimationSpeed = 1;
private Image image;
private bool animationState = false;
private void Start()
{
image = GetComponent<Image>();
}
private void Update()
{
if (animationState)
{
image.pixelsPerUnitMultiplier = Mathf.Lerp(image.pixelsPerUnitMultiplier, SmallSate + 0.05f, Time.deltaTime * AnimationSpeed);
if (image.pixelsPerUnitMultiplier >= SmallSate)
{
animationState = false;
}
}
else
{
image.pixelsPerUnitMultiplier = Mathf.Lerp(image.pixelsPerUnitMultiplier, LargeState - 0.05f, Time.deltaTime * AnimationSpeed);
if (image.pixelsPerUnitMultiplier <= LargeState)
{
animationState = true;
}
}
}
}
Your answer
Follow this Question
Related Questions
Ui scaling 1 Answer
UI fade with CanvasGroup vs of Image.color.alpha or Text.color.alpha performance 1 Answer
Disable and enable canvas group by pressing an UI button. (C#) 2 Answers
How to snap UI element anchor relative to image sprite? 2 Answers
Why is my texture2D screenshot coming out as a grey box? 1 Answer