- Home /
getting position from a script
i've been on this for hours now and i can't figure it out one bit, i am trying to get the position of the object from TileST but i can't figure it out here's my scripts
MoveST
function Update () {
var hit: RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButtonDown(0)) {
if(Physics.Raycast(ray,hit,50)){
if(hit.collider.tag == "flat"){
transform.position = new Vector3 (hit.transform.gameObject.GetComponent(TileST));
}}}}
TileST:
#pragma strict
var xlocation : float;
var zlocation : float;
function Update () {
xlocation = transform.position.x;
zlocation = transform.position.z;
}
Answer by robertbu · May 15, 2014 at 04:39 AM
The TileST component is not going to have a different position than the transform. That is the transform you are trying to access through the script is just another component on the same game object as the TileST component and it this case is 'hit.transform'. So you can just do:
transform.position = hit.transform.position;
Just for chuckles, if you wanted to get the position through TileST, it would be:
transform.position = hit.transform.GetComponent(TileST).transform.position;
Answer by Noob_Vulcan · May 15, 2014 at 04:47 AM
If u want the xlocation and zlocation from TIleSt then...
var tile_St :TileST
if(hit.collider.tag == "flat"){ tile_St=hit.transform.gameObject.GetComponent(TileST)); transform.position = new Vector3 (tile_St.xlocation,0,tile_St.zlocation); }
Your answer
Follow this Question
Related Questions
Why isn't this raycast working? 2 Answers
How do I change a clicked on GameObjects variable when a boolean (Next Turn) is true? 1 Answer
using Physics.Raycast to run functions on diffrent gameObjects? 1 Answer
GetComponent, Object Reference not set to an instance of an object 0 Answers
how to make one script change a variable in another scipt 2 Answers