Beispiel #1
0
 void updateFollower(Messageable follower, Messageable target)
 {
     if (follower == target)
     {
         return;
     }
     moveMessageableTowards(follower, target.transform.position);
 }
 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));
     }
 }
Beispiel #3
0
 void updateTarget(Messageable newTarget)
 {
     if (newTarget != null && newTarget != target && (newTarget.networkView.isMine))
     {
         if (target != null)
         {
             applyMaterial(target, neutralMaterial);
         }
         if (follower != null)
         {
             applyMaterial(follower, followerMaterial);
         }
         applyMaterial(newTarget, playerMaterial);
         target = newTarget;
     }
 }
Beispiel #4
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));
     }
 }
Beispiel #5
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]);
             }
         }
     }
 }
Beispiel #6
0
    private static void applyMaterial(Messageable o, Material m)
    {
        MeshRenderer mrMesh = o.GetComponent <MeshRenderer>();

        mrMesh.material = m;
    }
 private static void applyMaterial(Messageable o, Material m)
 {
     MeshRenderer mrMesh = o.GetComponent<MeshRenderer>();
     mrMesh.material = m;
 }
 void updateTarget(Messageable newTarget)
 {
     if (newTarget != null && newTarget != target && (newTarget.networkView.isMine)) {
         if(target != null) applyMaterial(target, neutralMaterial);
         if(follower != null) applyMaterial(follower, followerMaterial);
         applyMaterial(newTarget, playerMaterial);
         target = newTarget;
      	}
 }
 void updateFollower(Messageable follower, Messageable target)
 {
     if (follower == target) {
        return;
     }
     moveMessageableTowards(follower, target.transform.position);
 }
 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]);
            }
        }
     }
 }