- Home /
transform Vector3 help!
I need help how to do this logic on code
Vector3 myPosition;
myPosition = "Vector3 of this object"?
Answer by FLASHDENMARK · Nov 10, 2011 at 07:03 PM
Vector3 myPosition;
myPosition = transform.position;
You can call and use an objects position, rotation, scale(and much more) by referring the transform of an object.
Answer by Wentzel · Nov 10, 2011 at 06:14 PM
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Vector3 p;
void Awake() {
p[0] = 5; }
}
Access the x, y, z components using [0], [1], [2] respectively.
I use javaScript but this should work fine.
Why so complicated? This is way beyond the understanding of a rookie.
You are propably reading it wrong, First Vector3 is Assigned to the Variable p.
So p can be used as the base for the Coordinate values such as if you want the Y value moved p[1] = 2.
$$anonymous$$ore info http://unity3d.com/support/documentation/ScriptReference/Vector3.Index_operator.html
Your logic is right, but it is way to complicated. Since we are dealing with a Vector3 ins$$anonymous$$d of using arrays(?) access the x, y or z value(s) of the transform. If you want the y value changed use the y value of the transform ins$$anonymous$$d of using p[1] = 2;
He was just asking for help, he didn't say it must not be complicating.
Really it doesn't look like he is willing to learn, Good luck to nowhere.
This was not an attempt to offend you. If I did, I am sorry. I was just stating that this could be done more simply. If this works out for you please by all means continue to use this method.