public void ActionMaker() { switch (actionToDo) { case actionToDoWithTarget.none: break; case actionToDoWithTarget.attack: if (currentBlobTarget.alive) { DealDamageToBlob(); currentBlobTarget = null; } else { visualAnimator.SetTrigger("Attack"); currentBlobTarget = null; } break; case actionToDoWithTarget.drag: DropBlob(); DragBlob(); break; default: break; } actionToDo = actionToDoWithTarget.none; }
public void MovementManagement() { if ((this.transform.position - destination).sqrMagnitude > speed * Time.deltaTime + rangeMovement) { Vector3 direction = (destination - this.transform.position).normalized; this.transform.Translate(direction * speed * Time.deltaTime); //Rotation : Vector3 directionButWithoutY = direction; directionButWithoutY.y = 0; Quaternion quat = Quaternion.FromToRotation(Vector3.back, directionButWithoutY); visualAnimator.transform.rotation = quat; //Cool trick : make it with a lerp ? visualAnimator.SetBool("Walk", true); } else { destination = this.transform.position; visualAnimator.SetBool("Walk", false); if (actionToDo == actionToDoWithTarget.drop) { DropBlob(); actionToDo = actionToDoWithTarget.none; } } if (currentBlobTarget != null) { float distance = (this.transform.position - currentBlobTarget.transform.position).sqrMagnitude; if (distance < currentBlobTarget.rangeAttack * rangeMultiplier) { ActionMaker(); } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Input.mousePosition; mousePos.z = 10; Vector3 worldPosition = mainCamera.ScreenToWorldPoint(mousePos); //DEBUG//target.position = worldPosition; RaycastHit hit; // Does the ray intersect any objects excluding the player layer if (Physics.Raycast(mainCamera.transform.position, worldPosition - mainCamera.transform.position, out hit, 50f, layerMaskForMovement)) { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); // Debug.Log("Did Hit"); destination = hit.point; destination.y = -1; Blob blobHit = hit.collider.GetComponent <Blob>(); if (blobHit != null) { currentBlobTarget = blobHit; actionToDo = actionToDoWithTarget.attack; } } } if (Input.GetMouseButtonDown(1)) { Vector3 mousePos = Input.mousePosition; mousePos.z = 10; Vector3 worldPosition = mainCamera.ScreenToWorldPoint(mousePos); //DEBUG//target.position = worldPosition; RaycastHit hit; // Does the ray intersect any objects excluding the player layer if (Physics.Raycast(mainCamera.transform.position, worldPosition - mainCamera.transform.position, out hit, 50f, layerMaskForMovement)) { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); //Debug.Log("Did Hit"); destination = hit.point; destination.y = -1; Blob blobHit = hit.collider.GetComponent <Blob>(); if (blobHit != null) { currentBlobTarget = blobHit; actionToDo = actionToDoWithTarget.drag; } else if (currentDraggedBlob != null) { currentBlobTarget = null; //Go to drop it actionToDo = actionToDoWithTarget.drop; } } } MovementManagement(); }