Reputation: 1279
I am trying to change the position of a sprite through a script. Here is the code for trying to change it. I tried it through the SpriteRenderer and the Sprite itself.
void Update() {
checkMesh();
spriteRenderer.enabled = true;
spriteRenderer.transform.position.Set(10,10,1);
sprite.rect.Set(10, 10, 100, 100);
checkStart();
checkForEnd();
}
Here is how I am grabbing the references to Sprite and the renderer
spriteRenderer = this.GetComponentInChildren<SpriteRenderer>();
sprite = spriteRenderer.sprite;
I can't seem to find why it won't work. Here is an image of the Hierarchy
I am trying to move the image named "bigpaddle" under "Expand Paddle"
Any help is extremely appreciated.
Upvotes: 1
Views: 11984
Reputation: 168
I don't know if you are trying to set the parent or move the object, but:
transform.SetParent(transform)
transform.position = new Vector3(0,0,0)
Hope it helps!
Upvotes: 0
Reputation: 63
i am unfamiliar with position.set(), (dunno if it exits) but it think it expects a vector3.
normaly setting a position is done like this
transform.position = new Vector3(0, 0, 0);
Upvotes: 0
Reputation: 91
https://gamedev.stackexchange.com/questions/74891/unity-move-sprite-from-point-a-to-point-b
Reference this. I'm assuming you know about dragging+dropping scripts directly onto game objects and that it isn't the problem.
Edit: Recommend you change the tags to your question if you want more people weighing in; Unity doesn't use Java, it uses C#, a variant of Javascript, and an implementation of Python. unity3d
is the most relevant tag for you.
Upvotes: 1