Nos_E3ks
Nos_E3ks
CC#
Created by Nos_E3ks on 4/13/2023 in #help
❔ trying to get my Dialog system to be with a key press and not just walking into the npc, unity 2d
I've been trying for awhile now to make it so it works but, everything I do doesn't work. I have all the code, it works but when you walk into the npc, and I want to figure out how to do it when I walk up to the npc and press the Z key at the same time. thank you
7 replies
CC#
Created by Nos_E3ks on 8/31/2022 in #help
Trying to fade In and out Object
I've been stuck for awhile now, Been trying to figure out how to loop it and have it fade in and out.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fadeobj : MonoBehaviour {

void Update() {
var animation = 1;

if (animation == 1)
{
StartCoroutine(FadeOutObject());
}

if (animation == 2)
{
StartCoroutine(FadeInObject());
}
}
public IEnumerator FadeOutObject() {
while (this.GetComponent<Renderer>().material.color.a > 0)
{

Color objectColor = this.GetComponent<Renderer>().material.color;
float fadeAmount = objectColor.a - ( 2 * Time.deltaTime);
objectColor = new Color(objectColor.r, objectColor.g, objectColor.b, fadeAmount);
this.GetComponent<Renderer>().material.color = objectColor;
var animation = 2;
yield return null;
}
}

public IEnumerator FadeInObject() {
while (this.GetComponent<Renderer>().material.color.a < 0 )
{

Color objectColor = this.GetComponent<Renderer>().material.color;
float fadeAmount = objectColor.a - ( -2 * Time.deltaTime);

objectColor = new Color(Random.value, Random.value, Random.value);
this.GetComponent<Renderer>().material.color = objectColor;
var animation = 1;
yield return null;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class fadeobj : MonoBehaviour {

void Update() {
var animation = 1;

if (animation == 1)
{
StartCoroutine(FadeOutObject());
}

if (animation == 2)
{
StartCoroutine(FadeInObject());
}
}
public IEnumerator FadeOutObject() {
while (this.GetComponent<Renderer>().material.color.a > 0)
{

Color objectColor = this.GetComponent<Renderer>().material.color;
float fadeAmount = objectColor.a - ( 2 * Time.deltaTime);
objectColor = new Color(objectColor.r, objectColor.g, objectColor.b, fadeAmount);
this.GetComponent<Renderer>().material.color = objectColor;
var animation = 2;
yield return null;
}
}

public IEnumerator FadeInObject() {
while (this.GetComponent<Renderer>().material.color.a < 0 )
{

Color objectColor = this.GetComponent<Renderer>().material.color;
float fadeAmount = objectColor.a - ( -2 * Time.deltaTime);

objectColor = new Color(Random.value, Random.value, Random.value);
this.GetComponent<Renderer>().material.color = objectColor;
var animation = 1;
yield return null;
}
}
}
23 replies