Looks like the update is calling a method only once
Hey all I have got a trigger area that when the player enters it sets a bool in the player true that then makes pop-up an image using some static functions I made in a static utility class.The problem is that it calls only once or not at all these functions,the strange thing is that I already used them and they work fine. Here the class with the utility functions
public static class UtilityFunctions {
//mostra l'immagine
public static void ShowImage(Image img,float increase_scale)
{
if (img.rectTransform.localScale.x < 1 && img.rectTransform.localScale.y < 1 && img.rectTransform.localScale.z < 1)
{
img.rectTransform.localScale += new Vector3(increase_scale, increase_scale, increase_scale);
}
}
//there are other functions but that's what I'm using...
}
Here the simple script that makes pop up the image:
public class InteractableActive : MonoBehaviour {
GameObject player;
bambina_inputs bambina_inputs;
public Image interactable_img;
//Image interactable_button_img;
public float grandezza_rate;
int a=0;
// Use this for initialization
void Start () {
player = GameObject.Find("bambina");
bambina_inputs = player.GetComponent<bambina_inputs>();
}
// Update is called once per frame
void Update () {
//ingrandisce l'immagine,la fa apparire
if(bambina_inputs.can_interact)
{
/*UtilityFunctions.ResizeImage(interactable_img, UtilityFunctions.scelta.ingrandisci, 1, grandezza_rate, false); it is called once*/
UtilityFunctions.ShowImage(interactable_img, grandezza_rate);//it isn't called at all
Debug.Log("hey");//it is called normally
}
}
}
The class with the utility functions aren't in any gameobjects in the scene. The funniest thing is that I've got other scripts in other gameobjects that use these functions a lot of times and they work fine and they are normally called at each frame.What's wrong? What I must change to make it call these functions? I've been crashing my head on the keyboard for a lot of time,I really hope someone helps me. Thank you in advance :D
your best option is to debug
in the static function, and if they do get called, it just means that your if
statement is causing the problems.
No,there is a OnTriggerEnter2D that sets can_interact to true then a OnTriggerExit2D sets it to false when the player goes out of the trigger area
so i never used static classes so i don't know how do you planing to set interactable_img to interactable_img.gameObject.SetActive (false or true);
when the player enter exit the area .
I've solved,it's a little stupid error. If you see the function ShowImage() it works only if all the local scale axes are <0 but my image only had the x and y axis set to 0 and the z was 1,so the if didn't work.