- Home /
Question by
Chris12345 · Jun 23, 2012 at 02:30 PM ·
gameobjecttransform
How can i have it so i can drag and Game object from the hierarchy to the Inspector view user target?
How do i make this use a game object, instead of the Transform for the target? thanks for the help.
#pragma strict
var target : Transform;
var smoothTime = 0.3;
private var thisTransform : Transform;
private var velocity : Vector3;
var offsetAmountx : float = 10.00;
var offsetAmounty : float = 10.00;
function Start()
{
thisTransform = transform;
}
function Update()
{
thisTransform.position.x = Mathf.SmoothDamp( thisTransform.position.x,
target.position.x +offsetAmountx,velocity.x, smoothTime);
thisTransform.position.y = Mathf.SmoothDamp( thisTransform.position.y,
target.position.y +offsetAmounty,velocity.y, smoothTime);
}
Comment
Best Answer
Answer by delstrega · Jun 23, 2012 at 02:46 PM
Basically you'd use target.transform instead of target, since now target is a GameObject:
pragma strict
public var target: GameObject;
var smoothTime = 0.3;
private var thisTransform: Transform;
private var velocity : Vector3;
var offsetAmountx : float = 10.00;
var offsetAmounty : float = 10.00;
function Start()
{
thisTransform = transform;
}
function Update()
{
var x : float = Mathf.SmoothDamp(thisTransform.position.x,
target.transform.position.x +offsetAmountx,velocity.x, smoothTime);
var y : float = Mathf.SmoothDamp( thisTransform.position.y,
target.transform.position.y +offsetAmounty,velocity.y, smoothTime);
var newPos : Vector3 = Vector3(x, y, thisTransform.position.z);
thisTransform.position = newPos;
}
How can i have it so i can drag and Game object from the hierarchy to the Inspector view user target. why does it not let me drag it to there?
this is all i want to do How can i have it so i can drag and Game object from the hierarchy to the Inspector view user target. why does it not let me drag it to there?
Your answer
Follow this Question
Related Questions
Continuous detection of object using ray cast 2 Answers
Problems with Transform.Find and GameObject.find 1 Answer
A node in a childnode? 1 Answer
Trying to find objects. 1 Answer