- Home /
Problem Gameobject parent Tag with hit mouse
Hi! Mouse can press gameobject (tag) it gameobject attach gameobject.tag next press right with mouse to detach gameboject.tag with gameobject, only select in mouse with gameobject.tag, My script's error var Player : Transform;
function Update () {
if(Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(0)){
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit, 8020) && hit.transform.tag == "Wall")
{
if(Input.GetMouseButtonDown(0)){
Player.transform.parent = hit.gameObject.transform;
}
else
Player.transform.parent = null;
}
}
}
Thanks
where is "Player" defined? if "Player" is a Transform, you don't need
Player.transform.parent,
just say Player.parent
Answer by Seth-Bergman · Jul 27, 2012 at 11:40 AM
function Update () {
if(Input.GetMouseButtonDown(1)){
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit, 8020)){
if(hit.collider.tag == "Wall" && !Player.parent)
Player.parent == hit.transform;
}
}
if(Input.GetMouseButtonDown(0)){
Player.parent == null;
}
}
here's an example, assuming player is declared as Player : Transform (I think that's what you're saying), hard to tell what you're after, but this may be closer
Doesn't work, I press mouse to error "At line -1"
$$anonymous$$issingFieldException: Field 'UnityEngine.RaycastHit.gameObject' not found.
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_AnonStorey14.<>m_9 () 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)
Doesn't work me too my script... because nothing no attach gameobject, and error detach with gameobject.
Code error: UnassignedReferenceException: The variable Player of 'xxxx' has not been assigned. You probably need to assign the Player variable of the xxxx script in the inspector. xxxx.Update () (at Assets/xxxx.js:14)
Your answer
Follow this Question
Related Questions
How to instantiate an object inside parent using parent's scale 1 Answer
Resetting Ball Object to the original parent and position 2 Answers
transform.parent == null not working 1 Answer
[Solved] Problem with rotation on an Instantiated Object 0 Answers
transform.DetachChildren() is deactivating my children's scripts after detaching from the parent 1 Answer