c# - Transferring a Vector3 variable from one script (WayPointPositioner) to another and change it into a transform (Walking) -



c# - Transferring a Vector3 variable from one script (WayPointPositioner) to another and change it into a transform (Walking) -

i'm having bit of problem getting vector3 waypointposition other script called walking , changing transform target. troubles lie in fact i'm trying grab dynamic variable waypointpositioner (it changes depending on object clicked in stage , whether player overlaps waypoint) , import , utilize in script.

below code i'm using.

waypointpositioner

using unityengine; using system.collections; public class waypointpositioner : monobehaviour { public vector3 waypointposition = vector3.zero; private bool checkplayerwaypointcollision; void start() { } void ontriggerstay2d (collider2d other) { // check if collision occuring player character. if (other.gameobject.name == "player") { checkplayerwaypointcollision = true; } else { checkplayerwaypointcollision = false; } } //check if object clicked void onmousedown () { // if player, homecoming new position player move walking // else debug not if (checkplayerwaypointcollision == false) { debug.log ("object not colliding , retrieving position"); debug.log (waypointposition); debug.log (gameobject.name); waypointposition = new vector3 (transform.position.x, transform.position.y, 10); waypointposition = camera.main.screentoworldpoint(waypointposition); } else { debug.log ("object colliding, no motion needed"); } } }

walking

using unityengine; using system.collections; public class walking : monobehaviour { public transform target; public waypointpositioner waypointposition; public bool walkinganimation = false; private animator anim; void awake () { anim = getcomponent<animator> (); waypointposition = gameobject.findgameobjectwithtag ("waypoint").getcomponent<waypointpositioner> (); } void start () { } void update () { debug.log ("this in walking, wpp =" + waypointposition); } }

as can see i'm trying import waypointposition seperate class attached gameobjects called "waypoint" (in current layout empty objects circle colliders check if have been clicked). when run this, not getting vector, i'm getting name of lastly waypoint in hierarchy (i have 6 waypoints can clicked) , not vector.

i hope able help me / point out mistake. i'm still learning c# might've made unusual / odd assumption isn't working.

kind regards,

veraduxxz.

it looks invoking gameobject.findgameobjectwithtag("waypoint").getcomponent<waypointpositioner>(); retrieves component game object matches specified tag, type argument t derives monobehavior.

calling should give instance of waypointpositioner class, can pass whichever methods want, , interact vector3 like.

c# unity3d monodevelop

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -