- Home /
Please help me with Raycast
I want make pong tennis game and thi is supposed to be control of one platforms and 2p01 is name of colider i have this code connect with the platform. Can you help me? Please help me with this code I have connect it to
private var ray : Ray;
private var hit : RaycastHit;
function Update () {
if(Input.GetMouseButton(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit))
{
if (hit.collider != "2p01")
{
Move ();
}
}
}
}
function Move()
{
transform.position.x = ray.point.x;
}
}
ok... what are trying to "connect" to, what do you mean by connecting? (for all we know you trying to connect a face chat with $$anonymous$$risten Stewart)what are you having problems with? if you wondering where to Attach the script. attach to the 2p01 game object in your hierarchy and test it. if its not working or you get errors reply via the comments section.
I attach it and is saying this error i have problem withm moving the platform. $$anonymous$$issingFieldException: UnityEngine.Ray.point Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateGetter () Boo.Lang.Runtime.RuntimeServices.DoCreatePropGetDispatcher (System.Object target, System.Type type, System.String name) Boo.Lang.Runtime.RuntimeServices.CreatePropGetDispatcher (System.Object target, System.String name) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey17.<>m_C () Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.Dispatcher$$anonymous$$ey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cache$$anonymous$$eyName, System.Type[] cache$$anonymous$$eyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cache$$anonymous$$eyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
you didn't put the code in a Boo script did you?, that above is UnityScript(or Javascript). (does the icon in the Project window have a little Pacman ghost on it?)
Ray's don't have a 'point'. I'm guessing you want 'hit.point';
Answer by belvita · Nov 29, 2013 at 01:52 PM
make it more obvious it has to be
if(hit.collider.gameObject.tag=="your objects tag name")
also hit.point.x
change this if(Physics.Raycast(ray, hit)) to if(Physics.Raycast(ray,out hit))