void Update() { if (srHook && srHookPlatform && srRope) { srRope.transform.position = (srHook.transform.position + srHookPlatform.transform.position) / 2f; float angle = VectorUtil.GetAngle(srHook.transform.position, srHookPlatform.transform.position); float localScale = Vector3.Distance(srHook.transform.position, srHookPlatform.transform.position); srRope.transform.localEulerAngles = new Vector3(0, 0, angle + 90); srRope.size = new Vector2(0.25f, localScale * 4); } if (mIsRotating) { if (srHook.transform.eulerAngles.z > 70 && srHook.transform.eulerAngles.z <= 180) { mRotatingDirection = -1; } else if (srHook.transform.eulerAngles.z < 290 && srHook.transform.eulerAngles.z > 180) { mRotatingDirection = 1; } srHook.transform.Rotate(new Vector3(0, 0, mRotatingDirection * mRotateSpeed * Time.deltaTime)); } if (mLaunchStatus == 1) { float angles = srHook.transform.eulerAngles.z; float positionY = Mathf.Cos(Mathf.PI * angles / 180); float positionX = -Mathf.Sin(Mathf.PI * angles / 180); srHook.transform.Translate(positionX * mLaunchSpeed * Time.deltaTime, positionY * mLaunchSpeed * Time.deltaTime, 0, Space.World); //如果超过上限 则回收 if (srRope.size.y >= 50) { Recycle(); } } }
/// <summary> /// 发射子弹 /// </summary> public void LaunchBullet(Vector3 targetPositon, float force) { float angle = VectorUtil.GetAngle(transform.position, targetPositon); transform.Rotate(new Vector3(0, 0, 1), -90 + angle); if (rbBullet != null) { rbBullet.velocity = (targetPositon - transform.position).normalized * force; } }
/// <summary> /// 创建子弹 /// </summary> /// <param name="launchPositon"></param> /// <param name="force"></param> private void CreateBullet(MiniGameBarrageBulletTypeEnum bulletType, Vector3 targetPositon, float force) { Sprite spBullet = null; RuntimeAnimatorController animatorController = null; int damage = 10; bool hasDesAnim = false; switch (bulletType) { case MiniGameBarrageBulletTypeEnum.Stone: damage = 10; spBullet = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.spStone; animatorController = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.animatorControllerForStone; hasDesAnim = true; break; case MiniGameBarrageBulletTypeEnum.Arrow: damage = 10; spBullet = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.spArrow; animatorController = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.animatorControllerForArrow; break; case MiniGameBarrageBulletTypeEnum.Darts: damage = 20; spBullet = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.spDarts; animatorController = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.animatorControllerForDarts; break; case MiniGameBarrageBulletTypeEnum.Fireball: damage = 30; spBullet = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.spFireball; animatorController = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.animatorControllerForFireball; break; case MiniGameBarrageBulletTypeEnum.Egg: damage = 40; spBullet = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.spEgg; animatorController = MiniGameHandler.Instance.handlerForBarrage.miniGameBuilder.animatorControllerForEgg; hasDesAnim = true; break; } //设置发射器朝向角度 mAngelsTarget = VectorUtil.GetAngle(objEjector.transform.position, targetPositon); //创建子弹 GameObject objBullet = Instantiate(objBulletModel, objBulletContainer.transform); objBullet.SetActive(true); objBullet.transform.position = objEjector.transform.position; MiniGameBarrageBulletCpt bulletCpt = objBullet.GetComponent <MiniGameBarrageBulletCpt>(); bulletCpt.SetBulletData(bulletType, spBullet, animatorController, damage, hasDesAnim); //发射子弹 bulletCpt.LaunchBullet(targetPositon, force); }
public void SetData(Vector3 startPosition, Vector3 endPosition, float speedForEnemy) { this.speedForEnemy = speedForEnemy; RectTransform rtf = (RectTransform)transform; rtf.eulerAngles = new Vector3(0, 0, VectorUtil.GetAngle(startPosition, endPosition) - 90); rtf.anchoredPosition = startPosition; rtf .DOAnchorPos(endPosition, speedForEnemy) .SetEase(Ease.Linear) .OnComplete(() => { DestroyEnemy(); }); }
/// <summary> /// 前往看热闹 /// </summary> /// <param name="eventPosition"></param> public void IntentForGoToEvent(Vector3 eventPosition) { this.markPosition = eventPosition; float angle = 0; float circler = Random.Range(5f, 6f); if (Vector2.Distance(transform.position, eventPosition) <= 5) { angle = Random.Range(0f, 360f); } else { float tempAngle = VectorUtil.GetAngle(eventPosition, transform.position); angle = Random.Range(tempAngle - 45f, tempAngle + 45f); } movePosition = VectorUtil.GetCirclePosition(angle, eventPosition, circler); characterMoveCpt.SetDestination(movePosition); }