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 /
avatar image
0
Question by maroonrs2 · May 06, 2012 at 09:03 PM · instantiatevariablesonmousedowngetmousebuttondown

Mouse Over, Mouse Down, and Instantiate.

Hi there, I am making a tic tac toe game. The problem is, is not the sequences, but the mouse over event. Explain to be this section's errors:

 function OnMouseOver()
 {
     if(Input.GetMouseButtonDown(0))
     {
         if(Turn == "X")
         {
             Turn = "Y";
             Instantiate (XThingOne, renderer.transform.position, renderer.transform.rotation);
             Instantiate (XThingTwo, renderer.transform.position, renderer.transform.rotation);
         }
         else if(Turn == "Y")
         {
             Turn = "X";
             Instantiate (YThingOne, renderer.transform.position, renderer.transform.rotation);
         }
     }
 }

xThingOne, Two, and yThingOne all are prefabs. I need those to go in the box's position flat as they already were put into the prefab. Also, I need to know how i would locate some variables from a object in a script that are public. I Have declared Turn in another script. Thats why, because this script goes in many. THANKS A BUNCH!

Comment
Add comment · Show 8
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 Lo0NuhtiK · May 07, 2012 at 01:11 AM 1
Share

I love how you complain so much when people here that do help, help because they "want" to and not because they're obligated to do so. No one "has" to help you with anything, so be glad when/if they do and if they don't then figure it out yourself.

avatar image GC1983 · May 07, 2012 at 01:24 AM 0
Share

Patience and kindness are two virtues you must learn. You might not get any help for a while. Who knows. Just be polite and someone will eventually help.

Now, from what I see is that you have On$$anonymous$$ouseOver() with if statements checking to be clicked on. These are two different things. What errors are you getting? With your code, nothing is going to happen to On$$anonymous$$ouseOver because youre checking for something to be clicked.

avatar image Lo0NuhtiK · May 07, 2012 at 02:04 AM 1
Share

"....As seeing you didn't reading anything, i should be yellin at you. Good day."
@maroonrs2 6 $$anonymous$$utes ago

If you'd take a few $$anonymous$$utes to do a search of this board or look in the Script reference and read a bit, you'd find your answer easily. You spend more time bitching about how long it takes moderator's to post your crap out of the queue and how it's taking people too long to answer you than you'd spend if you put the slightest bit of effort into figuring out some of these things for yourself.

avatar image GC1983 · May 07, 2012 at 03:03 AM 1
Share

If you ask clear, legit questions and dont make comments in following, you wouldnt be getting negative votes on your questions. Ive gotten one negative only because I typod my question title, which was a bit confusing on what I was asking. You shouldnt be yelling at anyone for any reason. You should always be polite to people if you want them to give you the answers ins$$anonymous$$d of using the crazy thing called the internet to research.

You want to know how to reference scripts look up FindObject and GetComponent.

avatar image GC1983 · May 07, 2012 at 05:22 AM 0
Share

Youre welcome.

Show more comments

1 Reply

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

Answer by DaveA · May 07, 2012 at 02:26 AM

For one thing, you are checking to see if the mouse is down on the mouse-over handler. Take out that 'if mouse button' thing. But then, just mousing over a square would instantiate things. So really, this code should be in OnMouseDown instead. I don't know what you want to do in 'over'

Another, you don't need renderer.transform... just transform.... because the renderer and the transform both belong to 'this' object.

I assume that 'this' object is one of 9 squares. It would instantiate at the position of what it is that was clicked, but it's also taking the rotation of 'this' object. If you want the prefab's default rotation, just use Quaternion.identity instead of transform.rotation.

You instantiate two things in 'x' and one in 'y'. I assume you know what you're doing, that this is some sort of test code, right?

I would consider splitting the game control ('turn' handling) out of this and putting it in a 'game manager' script that handles the rules. Unless Turn is static, each square would have it's own copy of Turn, not good.

Also, not required, but convention has variables starting with a lower case letter. turn instead of Turn. Classes and Functions start with Capital letter.

Comment
Add comment · Show 2 · 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 maroonrs2 · May 07, 2012 at 04:34 AM 0
Share

Haha yea, I forgot about the mouse down part. Now this script would not go in the actual object just yet. I needed to find out how I could parse data from a data bank such as a script in a random part. Could you answer my other question on how I can edit variables in other scripts in other objects? $$anonymous$$ake sure it's noon proof. Sometimes 15year olds can b fooled like 12 year olds. Also thanks for sum$$anonymous$$g up on how the rotation thing works. I was on scripting reference and saw how to edit variables but they are horrible at actually understanding their users. Ty a lot!!!

avatar image maroonrs2 · May 07, 2012 at 12:19 PM 0
Share

refine your answer and ill give you the question.

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

9 People are following this question.

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

Related Questions

changing a variable with a gui button 1 Answer

Multiplying something.forward using a variable doesn't actually multiply, but multiplying by a number does. 1 Answer

Create objects in a selected area 2 Answers

multiple instantiate object script help 2 Answers

access instantiated object variable 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