Thanks for this! Would have never guessed to use Target Graphic with a Text field - that's a really misleading naming structure. Now that I know, can't believe it's so straight forward.
Amazing! I feel like that shoulda been more clear or come prefabbed out. I mean...who the heck woulda thought that the text could go into a graphic spot?!?
For mouse click on a sprite. There's two easy ways you can change the color to simulate a highlight or change size etc. Here are a couple samples. So first way would be to if (Input.GetMouseButtonDown(0)) { transform.GetComponent().sprite.color = "new color" // changes color transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); // changes size } if (Input.GetMouseButtonUp(0)) { transform.GetComponent().sprite.color = "new color" // change back to original color transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); // changes back to original size } or swap out sprite with a different sprite, Sprite sprite; Sprite highlightSprite; if (Input.GetMouseButtonDown(0)) { transform.GetComponent().sprite = highlightSprite; } if (Input.GetMouseButtonUp(0)) { transform.GetComponent().sprite = sprite; } Not sure if you need mouse click, but you can also do a OnMouseOver Sprite sprite; Sprite highlightSprite; void OnMouseOver() { transform.GetComponent().sprite = highlightSprite; } void OnMouseExit() { transform.GetComponent().sprite = sprite; } The other way, void OnMouseOver() { transform.GetComponent().sprite.color = "new color" transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); } you can also do a else , like so if(Input.GetMouseButtonDown(0)){ // held code } else{ // release code }
Although it may be more effective to use "Input.GetMouseButton(0)" instead of "Input.GetMouseButtonDown(0)" . GetMouseButton() Returns true for every frame that the mouse is being pressed. GetMouseButtonDown() (or GetMouseButtonUp() ) only return true during the ONE frame that the mouse button was pressed (or released).
Thanks for this! Would have never guessed to use Target Graphic with a Text field - that's a really misleading naming structure. Now that I know, can't believe it's so straight forward.
Amazing! I feel like that shoulda been more clear or come prefabbed out. I mean...who the heck woulda thought that the text could go into a graphic spot?!?
gracias es justo lo que ocupaba
Please tell me how to do the same thing but for a sprite (selection-highlighting) by mouse click.
Please!🙏
For mouse click on a sprite. There's two easy ways you can change the color to simulate a highlight or change size etc. Here are a couple samples.
So first way would be to
if (Input.GetMouseButtonDown(0))
{
transform.GetComponent().sprite.color = "new color" // changes color
transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); // changes size
}
if (Input.GetMouseButtonUp(0))
{
transform.GetComponent().sprite.color = "new color" // change back to original color
transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f); // changes back to original size
}
or swap out sprite with a different sprite,
Sprite sprite;
Sprite highlightSprite;
if (Input.GetMouseButtonDown(0))
{
transform.GetComponent().sprite = highlightSprite;
}
if (Input.GetMouseButtonUp(0))
{
transform.GetComponent().sprite = sprite;
}
Not sure if you need mouse click, but you can also do a OnMouseOver
Sprite sprite;
Sprite highlightSprite;
void OnMouseOver()
{
transform.GetComponent().sprite = highlightSprite;
}
void OnMouseExit()
{
transform.GetComponent().sprite = sprite;
}
The other way,
void OnMouseOver()
{
transform.GetComponent().sprite.color = "new color"
transform.GetComponent().sprite.localScale -= new Vector3(0.1f, 0.1f, 0.1f);
}
you can also do a else , like so
if(Input.GetMouseButtonDown(0)){
// held code
}
else{
// release code
}
Although it may be more effective to use "Input.GetMouseButton(0)" instead of "Input.GetMouseButtonDown(0)" . GetMouseButton() Returns true for every frame that the mouse is being pressed.
GetMouseButtonDown() (or GetMouseButtonUp() ) only return true during the ONE frame that the mouse button was pressed (or released).
@@thesenpaicode Wow, how much you wrote everything. Thank you very much! Now I will deal with it. ☺️
@@thesenpaicode This is what I really need to do looks like:
ruclips.net/video/mckl24tEwYk/видео.html
Only In 2d now
And After 3d I will need 😏🙂
i need a help , in the player move , i copy the playerPlatformerCotroller but didn't work , it's 2D btw
and the PhysicsObject too