void moveMessageableTowards(Messageable target, Vector3 destination)
 {
     if(target.transform.position.x - destination.x > moveThreshold) {
        target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_LEFT));
     }
     if(target.transform.position.x - destination.x < -moveThreshold) {
        target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_RIGHT));
     }
     if(target.transform.position.z - destination.z > moveThreshold) {
        target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_DOWN));
     }
     if(target.transform.position.z - destination.z < -moveThreshold) {
      target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_UP));
     }
 }
예제 #2
0
 void moveMessageableTowards(Messageable target, Vector3 destination)
 {
     if (target.transform.position.x - destination.x > moveThreshold)
     {
         target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_LEFT));
     }
     if (target.transform.position.x - destination.x < -moveThreshold)
     {
         target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_RIGHT));
     }
     if (target.transform.position.z - destination.z > moveThreshold)
     {
         target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_DOWN));
     }
     if (target.transform.position.z - destination.z < -moveThreshold)
     {
         target.receiveMessage(new WorldMessage(WorldMessage.MessageType.USE_ABILITY, Ability.MOVE_UP));
     }
 }
예제 #3
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hitData;
         if (Physics.Raycast(ray, out hitData))
         {
             Messageable newR = hitData.transform.GetComponent <Messageable>();
             updateTarget(newR);
         }
     }
     if (Input.GetMouseButton(1))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hitData;
         if (Physics.Raycast(ray, out hitData) && target != null)
         {
             moveMessageableTowards(target, hitData.point);
         }
     }
     if (Input.GetMouseButtonDown(2))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hitData;
         if (Physics.Raycast(ray, out hitData))
         {
             Instantiate(createe, hitData.point + new Vector3(0, createe.transform.lossyScale.y, 0), hitData.transform.rotation);
         }
     }
     if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift))
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hitData;
         if (Physics.Raycast(ray, out hitData))
         {
             Messageable newF = hitData.transform.GetComponent <Messageable>();
             if (follower != null)
             {
                 applyMaterial(follower, neutralMaterial);
             }
             if (newF != null && newF.networkView.isMine)
             {
                 applyMaterial(newF, followerMaterial);
                 applyMaterial(target, playerMaterial);
             }
             follower = newF;
         }
     }
     if (follower != null)
     {
         updateFollower(follower, target);
     }
     if (Input.anyKey)
     {
         if (Input.GetKey(KeyCode.Escape))
         {
             Rect r = new Rect(Screen.height / 2 - 100, Screen.width / 2 - 100, Screen.height / 2 + 100, Screen.width / 2 + 100);
         }
         foreach (var key in messageMap.Keys)
         {
             if (Input.GetKey(key) && target != null)
             {
                 target.receiveMessage(messageMap[key]);
             }
         }
     }
 }