Tuesday 15 June 2010

c# - Assets/Scripts/Unit2.cs(19,51): error CS0120: An object reference is required to access non-static member `CameraOperator.InvertMouseY(float) -



c# - Assets/Scripts/Unit2.cs(19,51): error CS0120: An object reference is required to access non-static member `CameraOperator.InvertMouseY(float) -

hi i'm making rts style game , having problem getting selecting , highlighting vehicles. here errors im having. help appreciated.

assets/scripts/unit2.cs(19,51): error cs0120: object reference required access non-static fellow member `cameraoperator.invertmousey(float)'

here script.

using unityengine; using system.collections; using system.collections.generic; public class unit2 : monobehaviour { public bool selected = false; public float flooroffset = 1; public float speed = 5; public float stopdistanceoffset = 0.5f; private vector3 movetodest = vector3.zero; private void update () { if (renderer.isvisible && input.getmousebuttondown (0)) { vector3 campos = camera.main.worldtoscreenpoint (transform.position); campos.y = cameraoperator.invertmousey(campos.y); "this line error" selected = cameraoperator.selection.contains (campos); if (selected) { renderer.material.color = color.red; } else { renderer.material.color = color.white; } if(selected && input.getmousebuttonup(1)) { vector3 destination = cameraoperator.getdestination(); if(destination != vector3.zero) { movetodest = destination; movetodest.y += flooroffset; } } } updatemove(); } private void updatemove() { if((movetodest != vector3.zero) && (transform.position != movetodest)) { vector3 direction = (movetodest - transform.position).normalized; direction.y = 0; transform.rigidbody.velocity = direction * speed; if(vector3.distance(transform.position, movetodest) < stopdistanceoffset) { movetodest = vector3.zero; } } else { transform.rigidbody.velocity = vector3.zero; } } } here cameraoperator script. using unityengine; using system.collections; using system.collections.generic; public class cameraoperator : monobehaviour { public texture2d selectionhighlight = null; public static rect selection = new rect (0, 0, 0, 0); private vector3 startclick = -vector3.one; private static vector3 movetodestination = vector3.zero; private static list<string> passables = new list<string> () {"floor"}; private void update () { checkcamera (); cleanup (); } public void checkcamera () { if (input.getmousebuttondown (0)) { startclick = input.mouseposition; } if (input.getmousebuttonup (0)) { startclick = -vector3.one; } if (input.getmousebutton (0)) { selection = new rect (startclick.x, invertmousey (startclick.y), input.mouseposition.x - startclick.x, invertmousey (input.mouseposition.y) - invertmousey (startclick.y)); if (selection.width < 0) { selection.x += selection.width; selection.width = -selection.width; } if (selection.height < 0) { selection.y += selection.height; selection.height = -selection.height; } } } public float invertmousey (float y) { homecoming screen.height - y; } private void cleanup () { if (!input.getmousebuttonup (1)) { movetodestination = vector3.zero; } } public static vector3 getdestination () { raycasthit hit; ray r = camera.main.screenpointtoray (input.mouseposition); if (movetodestination == vector3.zero) { if (physics.raycast (r, out hit)) { while (!passables.contains(hit.transform.gameobject.name)) { if (!physics.raycast (hit.transform.position, r.direction, out hit)) break; } } if (hit.transform != null) { movetodestination = hit.point; } } homecoming movetodestination; } }

you have not operator on vector. guessing want on entire evaluation, move ! outside of parentheses.

if(!(movetodest == vector3.zero) && !(transform.position == movetodest)) {

or alter operator utilize != operator:

if((movetodest != vector3.zero) && (transform.position != movetodest)) {

c#

No comments:

Post a Comment