using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Outline : MonoBehaviour
{
public float width;
private Renderer rend;
private float currentWidth;
private void Start()
{
rend = GetComponent<Renderer>();
currentWidth = rend.material.GetFloat("_Outline");
StartCoroutine(ChangeOutline());
}
private void Update()
{
//SetOutLineWidth(width);
}
public void SetOutLineWidth(float width)
{
rend.material.SetFloat("_Outline", width);
}
IEnumerator ChangeOutline()
{
float timeToWait = 3f;
while (currentWidth < width)
{
width += 0.01f;
SetOutLineWidth(width);
yield return new WaitForSeconds(timeToWait);
}
}
}
What I want to do is for example if I will set width variable value to 5 then change the value until the currentWidth is 5:
SetOutLineWidth(width);
If the currentWidth is 7 and I set width to 5 change the value from 7 to 5 slowly. If currentWidth is 7 and I set width to 10 again change it slowly to 10. What I did now is making the width value keep raising and setting the Outline non stop.
What I want to do in general is to make two modes:
Change the width value and set the Outline slowly according to the time once on one direction.
Like 1 but make it ping pong mode once the outline value reached to width change it back slowly to the first value outline was and then back to width nonstop.