• 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 /
avatar image
0
Question by Rebel8909 · Oct 31, 2014 at 10:57 PM · javascriptgetcomponent

Scripts not functioning or interacting.

Ok, so after the last time I posted this thanks to a few kind people, I saw that I had glazed over some just stupid things that I didn't think about when originally writing my scripts. Now I have removed those aspect and added a few log entry calls so whenever an action is performed it's logged.

Anyways to the point my scripts are still not interacting the way I wan't them to or not at all.

The script I have checking the number correct doesn't seem to work if I assign the adding of numbers to any function other than Update and if I set it in update it simply adds 1 to the number every frame the second the game is started.

The script in question:

 #pragma strict
 
 var correct : int = 0;
 var callTrue : boolean;    
 
 function Start() {
 
 correct = 0;
 callTrue = false;
 
 }
 
 function Update(){
 
 if(correct == 25){
 
     Debug.Log("Win");
     }
 }
 
 function Go(){
 
 correct = correct + 1;
 
 Update();
 
 }


And just in case you wan't the script making the calls to this one.

 #pragma strict
  
  var checkTrue = boolean;
  var correctCor : Vector3;
  var card : GameObject;
  
  function Update () {
  
  var ArrayScript : ArrayCorrect = GetComponent(ArrayCorrect);
  
  if(card.transform.position == correctCor){
         Debug.Log("I'm at the spot D:");
          ArrayScript.Go();
          Debug.Log("Adding one to ArrayCorrect.js");
      }
  }


I'm sure I'm just glazing over something but sometimes I genuinely need other people to just point things out for me that I would otherwise catch.

Thanks in advanced.

Comment
Add comment · Show 2
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 richyrich · Oct 31, 2014 at 11:21 PM 0
Share

At the moment you don't have a valid question. You have thus far stated you're not happy with how things are, but not said how you want them to change - how can anyone help you? What is it that you want to do that you need help with achieving?

avatar image MrSoad · Oct 31, 2014 at 11:27 PM 0
Share

Right, after reformatting your code, you are calling the Update() function. This function will be called automatically every frame by Unity anyway, it is a special function, calling it yourself will cause issues. You are calling "Go" from one Update which in turn calls an Update() on your other script, which will also run by itself when Unity calls Update during each frame...

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MrSoad · Oct 31, 2014 at 11:44 PM

Try this, I've stripped out everything that is not specific to your code above :

 #pragma strict
  
 var correct : int = 0; 

 //I've removed your Start() function
 //As far as this is concerned you
 //are setting the "correct" value above
 //and it is unnecessary. 
 
 function subGo(){
     correct = correct + 1;
 }
  

and :

 #pragma strict
 
 var correctCor : Vector3;
 var card : GameObject;
 var ArrayScript : ArrayCorrect;
 
 //Find your script here, not every frame!
 function Awake() {
 
     //I'm assuming your ArrayCorrect is on the same
     //object as this script.
     ArrayScript = GetComponent(ArrayCorrect);
 }
 
 function Update() {
 
     if (card.transform.position == correctCor) {
         ArrayScript.subGo();
     }

     if(ArrayScript.correct == 25) {
         Debug.Log("Win");
     }
 }

If you are having problems formatting your code here properly let us know, we can help, if you write your code like in your question then try and learn how to format it better. You, I, and everyone here will be able to read it better and figure out your problem faster if you do :)

Sorry all for the repeated edits, I have had a little bit of wine :)

Comment
Add comment · Show 1 · Share
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 Rebel8909 · Nov 05, 2014 at 07:25 PM 0
Share

Ok, for the most part this works. The counter doesn't go up until the object is moved to the correct coordinates but when it is the counter then just goes up by 1 every frame. How would I go around to having it add only 1 to the counter and then stopping it?

Edit: Never $$anonymous$$d I got it to work by having it destroy the script after poking the other script!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GetComponent: Easy help 1 Answer

Why do I have to call ToString() when fetching a String from another script? 2 Answers

access a script generically? 2 Answers

GetComponent not working normally. 1 Answer

How to enable/disable Javascript using a C# script? 1 Answer


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