- Home /
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!
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.
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.
"....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.
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.
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.
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!!!
Your answer
Follow this Question
Related Questions
changing a variable with a gui button 1 Answer
Create objects in a selected area 2 Answers
multiple instantiate object script help 2 Answers
access instantiated object variable 0 Answers