- Home /
How to assign x and y transform values of an gameobject to user defined variables?
I have created a project consisting of a sphere that needs to stick to the inner surface wall of a tunnel. So i have attached a script to the sphere:
using UnityEngine; using System.Collections;
public class GravityOnBall : MonoBehaviour { public float GravX; public float GravY; public float Mult;
void Start () {
Physics.gravity = new Vector3(GravX * Mult, GravY * Mult, 0);
}
}
What I want to do is to assign the x and y coordinate values of the transform position of gameobject which is the sphere to the variables GravX and GravY respectively.
Please help me to write a script for the above mentioned task.
Answer by Cherno · Mar 15, 2015 at 08:10 PM
Uhm... Are you sure you phrased your question correctly?
What I want to do is to assign the x and y coordinate values of the transform position of gameobject which is the sphere to the variables GravX and GravY respectively.
GravX = transform.position.x;
GravY = transform.position.y;
Feel free to mark the answer as acceped if it was indeed helpful :)
Your answer
Follow this Question
Related Questions
Transform Checking on all Array Objects (JS) 3 Answers
Accessing Vector3 variable from another script and having the object move towards that location 1 Answer
Following a gameObject, unexpected problems? 1 Answer
How to move two same Objects at the same place in different scenes? 1 Answer
Need insight on strange (simple) 2D object transform bug 0 Answers