void LateUpdate() { v3cameraLocation = transform.position; v3des = MovementXmasRB2D.GetLocation(); if (v3des.x > rightMost) { v3des.x = rightMost; } if (v3des.x < leftMost) { v3des.x = leftMost; } if (v3des.y > upMost) { v3des.y = upMost; } if (v3des.y < downMost) { v3des.y = downMost; } v2des = new Vector2(v3des.x, v3des.y); v2cameraLocation = new Vector2(v3cameraLocation.x, v3cameraLocation.y); v2damped = Vector2.SmoothDamp(v2cameraLocation, v2des, ref v2smoothVelocity, 0.5f, 1000f, Time.deltaTime); transform.position = new Vector3(v2damped.x, v2damped.y, -10f); }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { v3TouchLocation = Input.mousePosition; v3GroundLocation = Camera.main.ScreenToWorldPoint(new Vector3(v3TouchLocation.x, v3TouchLocation.y, 10f)); GameObjectUtility.customInstantiate(objTouch[0], new Vector3(v3GroundLocation.x, v3GroundLocation.y, -3f)); MovementXmasRB2D.SetDestination(MovementXmas.GetLocation(), new Vector3(v3GroundLocation.x, v3GroundLocation.y, 0f)); Ray ray = Camera.main.ScreenPointToRay(v3TouchLocation); //从摄像机发出到点击坐标的射线 RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, 1 << LayerMask.NameToLayer("Objects"))) { MovementXmasRB2D.SetDestination(MovementXmasRB2D.GetLocation(), new Vector3( hitInfo.collider.gameObject.transform.position.x, hitInfo.collider.gameObject.transform.position.y + hitInfo.collider.gameObject.transform.localScale.y / 2 + 100, 0f)); } } }