private void Update() { Animate(); CheckVisible(); if (updateFrameIndex > IMainMenu.GetUpdateFramesPerSecond() / 10) { if (canDoSomething) { AI(); } else { if (attacking && who_under_attack) { Vector3 look = Vector0.Flat(who_under_attack.trans.position - trans.position); Quaternion n = Quaternion.LookRotation(look); trans.rotation = Quaternion.Slerp(trans.rotation, n, Time.deltaTime * 3); } Stop(); } if (savable.health < 1 || (hasNoArms && hasNoLegs) || hasNoHead) { Die(); } updateFrameIndex = 0; } updateFrameIndex++; }
public void Equals() { // 各要素の比較はできません。 var v1 = new Vector0(3, 4); var v2 = new Vector0(3, 4); var v3 = new Vector0(4, 3); var ec = EqualityComparer <Vector0> .Default; Assert.IsTrue(ReferenceEquals(v1, v1)); // ReferenceEquals と同じです。 Assert.IsTrue(v1 == v1); Assert.IsTrue(Equals(v1, v1)); Assert.IsTrue(v1.Equals(v1)); Assert.IsTrue(ec.Equals(v1, v1)); Assert.IsFalse(ReferenceEquals(v1, v2)); Assert.IsFalse(v1 == v2); Assert.IsFalse(Equals(v1, v2)); Assert.IsFalse(v1.Equals(v2)); Assert.IsFalse(ec.Equals(v1, v2)); Assert.IsFalse(ReferenceEquals(v1, v3)); Assert.IsFalse(v1 == v3); Assert.IsFalse(Equals(v1, v3)); Assert.IsFalse(v1.Equals(v3)); Assert.IsFalse(ec.Equals(v1, v3)); }
public void Equals() { // == 演算子は定義されていませんが、Equals で各要素を比較できます。 var v1 = new Vector0(3, 4); var v2 = new Vector0(3, 4); var v3 = new Vector0(4, 3); var ec = EqualityComparer <Vector0> .Default; // 値型では、参照としての比較結果はつねに false です。 Assert.IsFalse(ReferenceEquals(v1, v1)); // ReferenceEquals と同じです。 Assert.IsFalse((object)v1 == (object)v1); Assert.IsTrue(Equals(v1, v1)); Assert.IsTrue(v1.Equals(v1)); Assert.IsTrue(ec.Equals(v1, v1)); // コンパイル エラー。 //Assert.IsTrue(v1 == v1); Assert.IsFalse(ReferenceEquals(v1, v2)); Assert.IsFalse((object)v1 == (object)v2); Assert.IsTrue(Equals(v1, v2)); Assert.IsTrue(v1.Equals(v2)); Assert.IsTrue(ec.Equals(v1, v2)); Assert.IsFalse(ReferenceEquals(v1, v3)); Assert.IsFalse((object)v1 == (object)v3); Assert.IsFalse(Equals(v1, v3)); Assert.IsFalse(v1.Equals(v3)); Assert.IsFalse(ec.Equals(v1, v3)); }
public static Vector3 FromCameraFlat(Vector3 origin) { Vector3 f = cameraTransformMain.forward; Vector3 r = cameraTransformMain.right; f = Vector0.Flat(f); r = Vector0.Flat(r); return(f * origin.z + r * origin.x); }
public void Spawn() { int l = 0; float max = maxCount; /*if (!ITimecycle.night) { * max = maxCount / 2; * }*/ if (human) { l = DataCenter.dataCenter.humans.Length; } else { l = DataCenter.dataCenter.zombies.Length; } if ((l < max && limit > 0) || (!IHuman.playerObj && human)) { GameObject sp = (GameObject)Resources.Load("Prefabs/ZombieRag_" + Random.Range(0, 1)); if (!human) { sp = Instantiate(sp, transform.position + (Vector3)Vector0.Flat(Random.onUnitSphere), Quaternion.identity, transform); IZombie z = sp.GetComponent <IZombie> (); z.findMode = isFinders; z.savable.health = 100 + IZombie.dead * 10; } else { if (IHuman.playerObj) { sp = (GameObject)Resources.Load("Prefabs/HumanRag"); sp = Instantiate(sp, transform.position + (Vector3)Vector0.Flat(Random.onUnitSphere), Quaternion.identity, transform); IHuman h = sp.GetComponent <IHuman> (); h.savable.name = "BOT"; Destroy(h.camObj); } else { sp = (GameObject)Resources.Load("Prefabs/Human"); sp = Instantiate(sp, transform.position + (Vector3)Vector0.Flat(Random.onUnitSphere), Quaternion.identity, transform); IHuman h = sp.GetComponent <IHuman> (); h.savable.name = "player"; IHuman.GetPlayer(); ITimecycle.UpdateCameras(); } } } if (limited) { limit -= 1; } if (!IsInvoking("Spawn")) { Invoke("Spawn", interval + Random.Range(0f, interval)); } }
private void Sinhro() { if (Input.GetButtonDown("Cancel")) { IMainMenu.ToMenu(); } weapon.texture = (Texture)Resources.Load("Sprites/Weapon_" + player.savable.currentWeapon); if (fire) { Fire(); } //SinhroCross (); Transform cm = IHuman.cameraMainParent; Transform fp = player.firePlace; float speed = Time.deltaTime * 8; if (cross) { rangeView = 30; Vector3 v = fp.position - fp.forward + fp.up * 0.02f; Debug.DrawRay(v, fp.forward); cm.position = Vector3.Slerp(cm.position, v, speed); } else { rangeView = 60; cm.localPosition = Vector3.Slerp(cm.localPosition, new Vector3(0, 0.0014f, 0.0013f), speed); } IHuman.cameraMain.fieldOfView = Mathf.Lerp(IHuman.cameraMain.fieldOfView, rangeView, 0.25f); health.text = "" + ((int)player.savable.health) + '\n' + "Зомби сейчас : " + DataCenter.dataCenter.zombies.Length; float t = ITimecycle.time; int sec = (int)((t - (int)t) * 60); string s = "" + sec; if (sec < 10) { s = "0" + sec; } killed.text = "Время : " + (int)t + ":" + s; IZombie z = IZombie.ZombieNearbyPosition(player.trans.position, 5, false); if (z) { Vector3 v = Vector0.Flat(z.trans.position - player.trans.position); v = player.trans.InverseTransformDirection(v); Quaternion q = Quaternion.LookRotation(v); zAngle = -135 - q.eulerAngles.y; } else { zAngle -= Time.deltaTime * 180; } radar.localEulerAngles = Vector3.forward * (zAngle); patronesType.texture = (Texture)Resources.Load("Sprites/Patrones_" + player.savable.currentWeapon); patrones.text = "" + player.savable.patrones_in [player.savable.currentWeapon] + "/" + player.savable.patrones_ [player.savable.currentWeapon]; }
public ActionFrame(Transform trans, Vector0 look, int strikes, float time) { this.destination = trans.position; this.lookPoint = look; this.strikesCount = strikes; this.timeLength = time; this.timeStart = Time.time; this.typeOfAction = ActionType.StrikeOnTime; this.body = trans; }
/// <summary> /// Only wait. /// </summary> /// <param name="trans">Trans.</param> /// <param name="look">Look.</param> /// <param name="strikes">Strikes.</param> /// <param name="time">Time.</param> public ActionFrame(Transform trans, float time) { this.destination = trans.position; this.lookPoint = trans.forward + trans.position + Vector3.up * IHuman.headHeight; this.strikesCount = 0; this.timeLength = time; this.timeStart = Time.time; this.typeOfAction = ActionType.StrikeOnTime; this.body = trans; }
} /// <summary> /// Move and look. Completed, when moved and looked. /// </summary> /// <param name="trans">Trans.</param> /// <param name="dest">Destination.</param> /// <param name="look">Look.</param> public ActionFrame(Transform trans, Vector0 dest, Vector0 look) { this.destination = dest; this.lookPoint = look; this.strikesCount = 0; this.timeLength = 1; this.timeStart = Time.time; this.typeOfAction = ActionType.MoveAndLook; this.body = trans; }
/// <summary> /// Only go to point, end only if destinetion has completed /// </summary> /// <param name="dest">Destination.</param> public ActionFrame(Transform trans, Vector3 dest) { this.destination = dest; this.lookPoint = dest + Vector3.up * IHuman.headHeight; this.strikesCount = 0; this.timeLength = 1; this.timeStart = Time.time; this.typeOfAction = ActionType.OnlyMove; this.body = trans; }
private void MoveAt(Vector3 direction) { if (onGround && !falled) { direction = Vector0.Flat(direction); Vector3 vel = direction * walkSpeed * walk_speed_k; /*if (body.velocity.magnitude < walkSpeed * walk_speed_k) { * body.AddForce (vel * walkForce * Time.deltaTime); * }*/ body.velocity = new Vector3(vel.x, body.velocity.y, vel.z); } }
public void Fall() { if (savable.name == "player") { anims.Play("Death"); falled = true; IZombie z = zombieNearby; if (z) { trans.rotation = Quaternion.LookRotation(Vector0.Flat(z.trans.position - trans.position)); } falledEulerY = trans.eulerAngles.y; } }
public Vector2 GetVectorForLegs() { Vector3 vel = Vector0.Flat(body.velocity); Vector3 dir = trans.InverseTransformDirection(vel); if (savable.name == "player") { dir = Joystick.move_input; dir = new Vector3(dir.x, 0, dir.y); } Vector2 tr = new Vector2(dir.x, dir.z); return(tr); }
private void LookAt() { if (currentFrame.typeOfAction == ActionFrame.ActionType.MoveAndLook || currentFrame.typeOfAction == ActionFrame.ActionType.MoveAndStrike || currentFrame.typeOfAction == ActionFrame.ActionType.MoveAndLook || currentFrame.typeOfAction == ActionFrame.ActionType.OnlyLook || currentFrame.typeOfAction == ActionFrame.ActionType.Strike || currentFrame.typeOfAction == ActionFrame.ActionType.StrikeOnTime || savable.name == "player") { if (!falled) { Vector3 look = Vector0.Flat(GetLookDirection()); trans.rotation = Quaternion.Slerp(trans.rotation, Quaternion.LookRotation(look), Time.deltaTime * 12); } } }
public static Vector0 Flat(Vector0 f) { f = new Vector3(f.x, 0, f.z).normalized; return(f); }