- Home /
fade-teleport not working
hello! thanks for viewing my question. i am making a 2d game and i have a little problem. when i made teleport script, i wanted for it to fade out so the screen would get black and then return to normal. teleporting is easy, i did it, but my problem is fade. i made 2 points (2 teleporters) from which when i hit f it fades in black, and another doesn't (while teleporting from first point screen turns black and then returns to normal (how i want) but from another it doesn't turn black). here is the script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class teleporter : MonoBehaviour {
public GameObject player;
public GameObject point1;
public GameObject point2;
bool inside;
public Text text;
public Image image;
public Color transparent;
Color aer;
public Color black;
bool ilaunched;
bool fade;
// Use this for initialization
void Start () {
inside = false;
ilaunched = false;
fade = false;
}
// Update is called once per frame
void Update () {
if (inside == true)
{
text.color = black;
if (Input.GetKeyDown(KeyCode.F))
{
player.transform.position = point2.GetComponent<Transform>().position;
ilaunched = true;
}
}
if (ilaunched == true && fade == false)
{
aer.a = aer.a + 0.1f;
}
if (aer.a > 3)
{
fade = true;
}
if (ilaunched == true && fade == true && aer.a < 0)
{
fade = false;
ilaunched = false;
}
if (ilaunched == true && fade == true)
{
aer.a = aer.a-0.1f;
}
image.color = aer;
}
private void OnTriggerStay2D(Collider2D collision)
{
if(collision.name== "player")
{
inside = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.name == "player")
{
inside = false;
text.color = transparent;
}
}
}
if i said something unclear, just reply and i will explain. thanks for seeing!
definitions : aer-holder of color value so i assign it at end to image color text-the text says "hit f to interact" image-it is a black image with alpha value of 0. point1-from where to teleport , point2-to where to teleport
What is your GameObject point1;
for ? You never use it. $$anonymous$$aybe it's part of your problem
point 1 is the point where player is standing to teleport , i thought i needed it when starting but later i did not need it. (plus this script is in point 1 so i dont know why i wrote it). it is not a part of the problem.
Answer by sandro_lord · Sep 08, 2018 at 10:36 AM
maybe i should make some kind of manager which will handle it from both teleport points? i will try it later, if it works i will tell you.