//------------------------------------------------------ private Vector3 getClossPoint(Vector3 p0, Vector3 s0, Vector3 p1, float spd) { Vector3 retPos = p0; float t0 = TmMath.CollideTime(p0, s0, p1, spd); if (t0 > 0.0f) { retPos += s0 * t0; } return(retPos); }
// Update is called once per frame void Update() { if (_rno == RNO.MOVE) { Vector3 vec = mDestLocalPos - transform.localPosition; float spd = 0.08f * Time.deltaTime; if (vec.magnitude < spd) { _rno = RNO.IDLE; transform.localPosition = mDestLocalPos; } Vector3 dirVec = vec.normalized * spd; transform.localPosition += dirVec; transform.rotation = TmMath.LookRotation2D(dirVec, Vector2.up); return; } if (mBulletTimer > 0) { mBulletTimer -= Time.deltaTime; } float distSqMin = distMinSq; GameObject em = null; GameObject[] ems = mGame.emList; foreach (GameObject go in ems) { float distSqc = (go.transform.position - transform.position).sqrMagnitude; if (distSqc < distSqMin) { distSqMin = distSqc; em = go; } } if (em != null) { Vector3 sizeVec = em.transform.position - transform.position; if (sizeVec.sqrMagnitude < distMinSq) { Vector3 emWorldSpd = em.GetComponent <enemyBase>().worldSpeed; sizeVec = getClossPoint(em.transform.position, emWorldSpd, transform.position, bulletSpeed) - transform.position; transform.rotation = TmMath.LookRotation2D(sizeVec, Vector2.up); } if (mBulletTimer <= 0.0f) { mBulletTimer += Random.Range(bulletInterval * 0.9f, bulletInterval * 1.1f); GameObject bl = GameObject.Instantiate(bulletPrefab, transform.position, transform.rotation) as GameObject; bl.tag = "tagBullet"; bl.transform.parent = transform.parent; bulletParam param = new bulletParam(bulletSpeed, 1.0f, bulleteLifeTime); bl.SendMessage("SM_SetBulletSpeed", param); } } }
// Update is called once per frame void Update() { if (mPosList == null) { return; } Vector3 posOld = transform.position; mLocalPosOld = transform.localPosition; switch (_rno) { case RNO.IDLE: break; case RNO.MOVE: if (mDistId < mPosList.Count) { Vector2 nowPos = transform.localPosition; Vector2 nextPos = mPosList[mDistId]; float spd = mLocalSpeedScalar * Time.deltaTime; if ((nowPos - nextPos).magnitude < spd * 2.0f) { mDistId++; } else { Vector2 movePos = transform.localPosition; mLocalSpeed = (nextPos - nowPos).normalized * mLocalSpeedScalar; movePos += mLocalSpeed * Time.deltaTime; transform.localPosition = movePos; transform.rotation = Quaternion.Lerp(transform.rotation, TmMath.LookRotation2D(mLocalSpeed, Vector2.up), 0.1f); } } else { Destroy(gameObject); } break; case RNO.EXPLODE: if ((mAnm.animFlag & 1) != 0) { Destroy(gameObject); } break; } mWorldSpeedVec = (transform.position - posOld) / Time.deltaTime; }