Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Danisuper · Mar 28, 2016 at 12:55 AM · c#update

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MewEight · Mar 28, 2016 at 02:54 AM 0
Share

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.

avatar image Ali-hatem · Mar 28, 2016 at 12:13 PM 0
Share

does can_interact always true ?

avatar image Danisuper Ali-hatem · Mar 28, 2016 at 04:54 PM 0
Share

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

avatar image Ali-hatem Danisuper · Mar 28, 2016 at 05:44 PM 0
Share

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 .

avatar image Danisuper · Mar 28, 2016 at 05:48 PM 0
Share

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.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with Async 0 Answers

why OnTriggerEnter is not work if with void Update 2 Answers

MonoBehaviour Update called twice, fields being set to null 0 Answers

FixedUpdate and Update not working in script 0 Answers

How do you execute code every X angles reliably? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges