Hi, all . I have 3 sprites named A,B,C. The C is hide at first, Now I wish after press A with B together, the C will appear, how to write the script? thank you !
here is my code but not correct:
var s1:GameObject;
var s2:GameObject;
var s3:GameObject;
function OnClick(){
s1.
Not really sure what you mean by ‘When i press A and B together’, since these are gameobjects in your game. but maybe you’re looking for something like this?
var A : GameObject;
var B : GameObject;
var C : GameObject;
function Start()
{
C.active = false;
}
function Update()
{
if(Input.GetKey(KeyCode.A) Input.GetKey(KeyCode.B)){
C.active = true;
}
}
This will turn the inactive C-object (defined in the Inspector) from invisible to visible, when the A and B BUTTONS are pressed at the same time…
If you mean that you want to click the same two sprites at the same time, I have no idea how you would want to do that.
But if you want to click one of them, so that it bcomes “active” or something, and then click the other one, then the third one appears, you should use some kind of boolean.
You would also want to make a raycast, so that you can check if you are actually clicking the sprites.
Look here for information on raycasting:
Raycasting will send out a ray in a direction from an origin. You can then use this ray so check if you are ‘hitting’ or ‘clicking’ the sprites.
So if you DO ‘click’ one of the two sprites, you can turn its boolean on, and make the third visible, if both of the other booleans are true.