I have a variable called pivot which is used in a rotatearound script. I want this variable to be any gameobject that is hit by a ray. Is there a way to do this?
for example...not actual code btw
if(user presses key)
Rotate object forward(player.position,hit gameobject.forward, 90,1);
Gave it a shot myself but I am currently left with an error
NullReferenceException: Object reference not set to an instance of an object
var Player : Transform;
var rotateAmount = 90;
var controller : CharacterController;
var Hit : RaycastHit;
function Start(){
}
function FixedUpdate (){
//casts a ray from camera to point in world
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
// If the controller is grounded and the ray hits an object; then you can Rotate walls
if ((controller.isGrounded) && (Physics.Raycast (ray, Hit, 50))) {
canRotate =true;
var pivot = Hit.collider;
if(Input.GetMouseButtonDown(1))
RotateObjectForward(Player.position,Hit.collider.gameObject.forward, 90,1);
if(Input.GetMouseButtonDown(0))
RotateObjectForward(Player.position,Hit.collider.gameObject.forward,90,1);
}