I can't seem to apply a Vector.Lerp because the var buildingObject is a GameObject and not Transform. how can I convert it into a Transform purely for the purpose of making it smooth move, without actually changing the var type.
var buildingObject : GameObject;
var myGround : Transform;
var smooth = 5.0;
function Update () {
checkForBuilding();
}
function checkForBuilding() {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100.00) && hit.collider.gameObject.CompareTag("CursorSnap")){
buildingObject.transform.position = hit.point;
}
}
returns the error BCE0020: An instance of type 'UnityEngine.Transform' is required to access non static member 'position'. maybe i've interpreted it wrong.
It shouldn't matter that the variable is a game object, since game objects inherently have transforms. Just make sure what you're using the Vector3.Lerp on is buildingObject.transform.position or .rotation
Make sure in your lerp that you use
transform.position
NOT
Transform.position
Transform with a capital 'T' is a type, like integer or float. The compiler wants to know what transform to use.
transform with a lowercase 't' refers to whatever transform this script is attached to.
In addition, it looks like you're trying to move the building smoothly to the hit.point. if thats the case, you may want to use this instead:
Lerp has the parameters (from, to, speed/time), so you'll want to use its position, not the script transform's position (assuming you're not running this script from that building object).
The effect this has will be a decelerating Lerp. If you want a smooth A to B without slowing down much, consider SmoothDamp instead :)