- Home /
The type or namespace name 'ClickedEventArgs' could not be found (are you missing a using directive or an assembly reference?) its part of the steamvr_teleport script.how do i solve it?
iam trying to teleport the camera rig using basic teleport script steamvr_teleport script and using a laser pointer to navigate. iam not able to solve this error "The type or namespace name 'ClickedEventArgs' could not be found (are you missing a using directive or an assembly reference?)"
using UnityEngine; using System.Collections;
public class SteamVR_Teleporter : MonoBehaviour { public enum TeleportType { TeleportTypeUseTerrain, TeleportTypeUseCollider, TeleportTypeUseZeroY }
public bool teleportOnClick = false;
public TeleportType teleportType = TeleportType.TeleportTypeUseZeroY;
Transform reference
{
get
{
var top = SteamVR_Render.Top();
return (top != null) ? top.origin : null;
}
}
void Start()
{
var trackedController = GetComponent<SteamVR_TrackedController>();
if (trackedController == null)
{
trackedController = gameObject.AddComponent<SteamVR_TrackedController>();
}
trackedController.TriggerClicked += new ClickedEventHandler(DoClick);
if (teleportType == TeleportType.TeleportTypeUseTerrain)
{
// Start the player at the level of the terrain
var t = reference;
if (t != null)
t.position = new Vector3(t.position.x, Terrain.activeTerrain.SampleHeight(t.position), t.position.z);
}
}
void DoClick(object sender, ClickedEventArgs e)
{
if (teleportOnClick)
{
// First get the current Transform of the the reference space (i.e. the Play Area, e.g. CameraRig prefab)
var t = reference;
if (t == null)
return;
// Get the current Y position of the reference space
float refY = t.position.y;
// Create a plane at the Y position of the Play Area
// Then create a Ray from the origin of the controller in the direction that the controller is pointing
Plane plane = new Plane(Vector3.up, -refY);
Ray ray = new Ray(this.transform.position, transform.forward);
// Set defaults
bool hasGroundTarget = false;
float dist = 0f;
if (teleportType == TeleportType.TeleportTypeUseTerrain) // If we picked to use the terrain
{
RaycastHit hitInfo;
TerrainCollider tc = Terrain.activeTerrain.GetComponent<TerrainCollider>();
hasGroundTarget = tc.Raycast(ray, out hitInfo, 1000f);
dist = hitInfo.distance;
}
else if (teleportType == TeleportType.TeleportTypeUseCollider) // If we picked to use the collider
{
RaycastHit hitInfo;
hasGroundTarget = Physics.Raycast(ray, out hitInfo);
dist = hitInfo.distance;
}
else // If we're just staying flat on the current Y axis
{
// Intersect a ray with the plane that was created earlier
// and output the distance along the ray that it intersects
hasGroundTarget = plane.Raycast(ray, out dist);
}
if (hasGroundTarget)
{
// Get the current Camera (head) position on the ground relative to the world
Vector3 headPosOnGround = new Vector3(SteamVR_Render.Top().head.position.x, refY, SteamVR_Render.Top().head.position.z);
// We need to translate the reference space along the same vector
// that is between the head's position on the ground and the intersection point on the ground
// i.e. intersectionPoint - headPosOnGround = translateVector
// currentReferencePosition + translateVector = finalPosition
t.position = t.position + (ray.origin + (ray.direction * dist)) - headPosOnGround;
}
}
}
}
changing ClickedEventArgs to clickedEventArgs also doesn't wort.
using UnityEngine; using System.Collections;
public class S$$anonymous$$mVR_Teleporter : $$anonymous$$onoBehaviour { public enum TeleportType { TeleportTypeUseTerrain, TeleportTypeUseCollider, TeleportTypeUseZeroY }
public bool teleportOnClick = false;
public TeleportType teleportType = TeleportType.TeleportTypeUseZeroY;
Transform reference
{
get
{
var top = S$$anonymous$$mVR_Render.Top();
return (top != null) ? top.origin : null;
}
}
void Start()
{
var trackedController = GetComponent<S$$anonymous$$mVR_TrackedController>();
if (trackedController == null)
{
trackedController = gameObject.AddComponent<S$$anonymous$$mVR_TrackedController>();
}
trackedController.TriggerClicked += new ClickedEventHandler(DoClick);
if (teleportType == TeleportType.TeleportTypeUseTerrain)
{
// Start the player at the level of the terrain
var t = reference;
if (t != null)
t.position = new Vector3(t.position.x, Terrain.activeTerrain.SampleHeight(t.position), t.position.z);
}
}
void DoClick(object sender, ClickedEventArgs e)
{
if (teleportOnClick)
{
// First get the current Transform of the the reference space (i.e. the Play Area, e.g. CameraRig prefab)
var t = reference;
if (t == null)
return;
// Get the current Y position of the reference space
float refY = t.position.y;
// Create a plane at the Y position of the Play Area
// Then create a Ray from the origin of the controller in the direction that the controller is pointing
Plane plane = new Plane(Vector3.up, -refY);
Ray ray = new Ray(this.transform.position, transform.forward);
// Set defaults
bool hasGroundTarget = false;
float dist = 0f;
if (teleportType == TeleportType.TeleportTypeUseTerrain) // If we picked to use the terrain
{
RaycastHit hitInfo;
TerrainCollider tc = Terrain.activeTerrain.GetComponent<TerrainCollider>();
hasGroundTarget = tc.Raycast(ray, out hitInfo, 1000f);
dist = hitInfo.distance;
}
else if (teleportType == TeleportType.TeleportTypeUseCollider) // If we picked to use the collider
{
RaycastHit hitInfo;
hasGroundTarget = Physics.Raycast(ray, out hitInfo);
dist = hitInfo.distance;
}
else // If we're just staying flat on the current Y axis
{
// Intersect a ray with the plane that was created earlier
// and output the distance along the ray that it intersects
hasGroundTarget = plane.Raycast(ray, out dist);
}
if (hasGroundTarget)
{
// Get the current Camera (head) position on the ground relative to the world
Vector3 headPosOnGround = new Vector3(S$$anonymous$$mVR_Render.Top().head.position.x, refY, S$$anonymous$$mVR_Render.Top().head.position.z);
// We need to translate the reference space along the same vector
// that is between the head's position on the ground and the intersection point on the ground
// i.e. intersectionPoint - headPosOnGround = translateVector
// currentReferencePosition + translateVector = finalPosition
t.position = t.position + (ray.origin + (ray.direction * dist)) - headPosOnGround;
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612204126im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there any way to mirror a non unity application 0 Answers
APK Can't be open in Android system microphone 0 Answers
How to check that only one key is pressed 2 Answers
Teleporting Objects,Teleporting Object 0 Answers
how to make teleporting marker 0 Answers