That will allow you to post code on the forums in a more readable and nicer format
Okay, there’s no need to use a ‘newSprite’ variable if you already have the sprite linked/referenced. That wouldn’t make it not work, it’s just not required. Do you have any errors when you’re doing this?
You should also make a variable for your “P2” game object and drag & drop it in the inspector if you can.
If you cannot, you should at least look it up at cache it in Start() and use the variable later, instead of repeatedly using ‘Find’ which is a slow method.
Well, I asked if there are any errors, because if everything is connected & referenced correctly, the script should be working.
Does the method get called? Do you know it’s running for sure?
Well, my way is the same way as the one you wrote, including the adjustments I mentioned in my previous post.
I mean I created a very similar script and even tried it and it’s working…Think I have since deleted it, but I’m sure that’s because it was right and I didn’t need it lol
k man well that’s a problem. Remove that line with Find “P2” thing. Remove the “newsprite” line entirely (unnecessary).
make a new public variable: public Sprite newSprite; (and drag the P2 into that in the inspector)
Then just try on the line :
theImage.sprite = newSprite;
I think that’s it.
Note: You can’t “GameObject.Find” an asset. You can reference your sprite, in this case, in a variable in the inspector, or use Resources.Load() if it’s in the right folder… but you can’t just call GameObject.Find on the name of an asset.
Still long way heheheh now i should think how make my player camera swipe up , down, left , right when touch my phone screen ANY IDEA I’m trying create shooting game