private static IEnumerator PlayerReborn(float sec = 1.2f) { yield return(new WaitForSeconds(sec)); yield return(Player.Create(Data.PlayerId, p => { MainPlayer = p; //从屏幕外移动进来 p.transform.position = Vector2Fight.New(0, -110); p.transform.DOMove(Data.PlayerBornPos, 0.5f).SetEase(Ease.Linear); //给5秒无敌时间 p.SetInvincibleTime(5f); })); }
public override void OnUpdate() { base.OnUpdate(); if (Time.time > _nextMoveTime) { _textMoveLeft = !_textMoveLeft; _nextMoveTime = Time.time + 5f; if (_textMoveLeft) { Master.MoveToTarget(Vector2Fight.New(-75f, 80f), 0.3f); } else { Master.MoveToTarget(Vector2Fight.New(75f, 80f), 0.3f); } } }
//创建怪物 public static IEnumerator Create(int enemyId, float bornX = 0f, float bornY = 150f) { var deploy = TableUtility.GetDeploy <EnemyDeploy>(enemyId); var gameObj = new GameObject(deploy.name); gameObj.SetActiveSafe(false); gameObj.transform.SetParent(null); yield return(Yielders.Frame); //创建显示模型 var model = new GameObject(deploy.name + "_model"); var mainSprite = model.AddComponent <SpriteRenderer>(); mainSprite.sortingOrder = SortingOrder.Enemy; mainSprite.material = new Material(GameSystem.DefaultRes.CommonShader); model.transform.SetParent(gameObj.transform, false); yield return(Yielders.Frame); //设置贴图 var enemy = deploy.isBoss ? gameObj.AddComponent <Boss>() : gameObj.AddComponent <Enemy>(); for (int i = 0; i < deploy.resoureIds.Length; i++) { var resourceId = deploy.resoureIds[i]; yield return(TextureUtility.LoadResourceById(resourceId, sprites => { enemy.SpriteDic[(EnemyMoveStyle)i] = sprites; })); } //Collider var collider = gameObj.AddComponent <CircleCollider2D>(); collider.radius = deploy.radius; collider.isTrigger = true; //init enemy.Material = mainSprite.material; enemy.transform.position = Vector2Fight.New(bornX, bornY); enemy.Init(mainSprite, deploy); gameObj.SetActiveSafe(true); }
public override void OnFixedUpdate() { base.OnFixedUpdate(); if (!CanShoot || Master.IsDead) { return; } FireBlueBullet(); FireBulletRed(); //左右移动 if (Time.time - _lastMoveTime > Random.Range(8, 15)) { _moveLeft = !_moveLeft; Master.MoveToTarget(Vector2Fight.New(_moveLeft ? -60f : 60f, 50f), 0.4f); _lastMoveTime = Time.time; } }
public override void Init(Enemy enemy) { base.Init(enemy); Master.MoveToTarget(Vector2Fight.New(0, 50), 3); }