Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Aug 20, 2013 at 02:06 AM by Benproductions1 for the following reason:

The question is answered in the comments

This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by harrietradcliffe · Aug 19, 2013 at 02:38 PM · positionrandomscoreadd

Click object and it will randomly change its position + add score

Hi we have this code for S_Click.js

 private var button: GameObject;
 
 private var ScoresText: GameObject;
 
 
 
 function Start(){
 
 
 
 ScoresText= GameObject.FindGameObjectWithTag("Player") ;
 
 button= GameObject.FindGameObjectWithTag("Finish") ;
 
 
 
 
 
 }
 
 
 
 function Update()
 
 {
 
     if(Input.GetMouseButtonDown(0))
 
     {
 
         var hit : RaycastHit;
 
         var ray : Ray =Camera.main.ScreenPointToRay(Input.mousePosition);
 
         
 
         if(Physics.Raycast(ray,hit))
 
         {
 
             ScoresText.GetComponent(S_Score).score+=1;
 
             if(hit.transform.tag == "Finish")
 
             {
 
                 var position =Vector3(Random.Range(-6,6),Random.Range(-6,6),0);
 
                 
 
                 //Destroy(this.gameObject);
 
                 hit.transform.position=position;
 
                 
 
             }
 
         }
 
     }
 
 }

and then for the S_Score.js

 var ScoresText: TextMesh;
 
 var score=0;
 
 function Update(){
 
     ScoresText.text="$ :      " + score.ToString();
 
     if (score == 15){
 
     print ("ok");
 
     }
 
     }

what could be so wrong? when I click the object, it should add 1 to the score... it's already changing its position.

thanks iff you help me!

Comment
Add comment · Show 4
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 robertbu · Aug 19, 2013 at 02:46 PM 0
Share

I could not see anything that would cause your code not to add 1, so I tested it in Unity. It worked fine for me including adding 1 to the score and displaying the new score.

avatar image harrietradcliffe · Aug 19, 2013 at 03:05 PM 0
Share

really? uhhh... why is it not working on me??? :''(

avatar image robertbu · Aug 19, 2013 at 03:21 PM 0
Share

I have no idea. I started with a new scene with just a 3D text object and a cube. I put the first script on the cube and tagged it "Finish". I put the second script on the 3D text object, dragged the 3D text to the ScoresText variable and tagged the game object 'Player'. You might try this with a new scene to see if it works for you.

avatar image harrietradcliffe · Aug 19, 2013 at 03:31 PM 0
Share

okayyy... i tried this and it worked for me! thanks so much robertbu! =))

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Random Position For GameObject 1 Answer

[Beginner] Using Random.Range in initial game object position 1 Answer

Spawn GameObjects without overlap 1 Answer

I want to change the object position random in five particular position only. 0 Answers

Instatiating a prefab in a random position 0 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