Im using a raycast, putting its RaycastHit
into a variable called raycastHit
, using that to get the raycastHit.transform.name
, could i then use the information from the name of the gameObject
to move its position? Or if not, could i get the information from the raycastHit
to instead move it straight away? (outside of the function of the raycast) I already looked for an answer, but ive been only finding results on how to move any gameObject
.
EDIT1: my current version of the void:
public RaycastHit raycastHit;
private void HandleHookShotStart()
{
if (TestInputDownHookShot())
{
int gm = LayerMask.NameToLayer("Ground");
int lwm = LayerMask.NameToLayer("LightWeight");
int layers = 1 << gm | 1 << lwm;
if (Physics.Raycast(Shoulder.transform.position, cam.transform.forward, out raycastHit, float.PositiveInfinity, layers))
{
//Hit Something
debugHitpointTransform.position = raycastHit.point;
hookshotPosition = raycastHit.point;
hookShotSize = 0f;
HookShotTransform.gameObject.SetActive(true);
HookShotTransform.localScale = Vector3.zero;
if (raycastHit.collider.gameObject.layer == gm)
{
Debug.Log("ground");
hitType = HitType.Ground;
}
else if (raycastHit.collider.gameObject.layer == lwm)
{
//Debug.Log("lightweight");
hitType = HitType.Lightweight;
goToMove = raycastHit.collider.gameObject;
string raycastHitObjectname = goToMove.name;
}
state = State.HookShotThrown;
}
}
}
EDIT2:
private void HandleHookShotGrab()
{
GameObject raycastHitObject = GameObject.Find(raycastHitObjectName);
}
error is on raycastHitObjectName
error:
CS0103 the name 'raycastHitObjectName' does not exist in the current context