private static void DrawPlayerPosition(PlayerNew player) { DrawUtil.DrawText("Player Position: " + pos.x + " , " + pos.y); GUILayout.BeginHorizontal(); xString = GUILayout.TextField(xString); yString = GUILayout.TextField(yString); GUILayout.EndHorizontal(); if (GUILayout.Button("Set Player Position")) { float x; float y; if (float.TryParse(xString, out x) && float.TryParse(yString, out y)) { Rigidbody2D rigidbody = player.GetComponent <Rigidbody2D>(); if (rigidbody != null) { rigidbody.position = new Vector2(x, y); } } } DrawUtil.DrawText("Player Velocity: " + vel.x + " , " + vel.y); }
public static void OnFixedUpdate(float dt) { GameManager gm = GameManager.instance; if (gm == null) { return; } PlayerNew player = gm.Player; if (player == null) { return; } Rigidbody2D rigidbody = player.GetComponent <Rigidbody2D>(); if (rigidbody != null) { pos = rigidbody.position; vel = rigidbody.velocity; if (noclip) { player.playerState = PlayerNew.PlayerState.isDead; rigidbody.isKinematic = true; rigidbody.position += new Vector2(moveX * dt * Main.settings.NoclipSpeed, moveY * dt * Main.settings.NoclipSpeed); } else if (noclipLast) { player.playerState = PlayerNew.PlayerState.isIdle; rigidbody.isKinematic = false; } noclipLast = noclip; } }
void Update() { timeSinceLastAttack += Time.deltaTime; float curHealth = GetComponent <Health>().CurrentHealth; if (curHealth <= 0) { MonsterHealth = 0; isDead = true; } if (isDead) { player.AddExp(expValue); string nameOfMobToSend = monsterType == MonsterType.Normal ? NameOfMob : "BOSS" + NameOfMob; Messenger <string> .Broadcast("MonsterKilled", nameOfMobToSend); //Destroy all floating text attached to this FloatingTextGUI[] floatingTexts = GetComponentsInChildren <FloatingTextGUI>(); for (int i = 0; i < floatingTexts.Length; i++) { Destroy(floatingTexts[i].gameObject, 0.5f); } DropLoot(); Destroy(gameObject); } else { if (inCombat) { EnableCombat = true; } else { EnableCombat = false; } if (isStunned) { EnableCombat = false; } if (isUseless) { return; } if (EnableCombat) { float angleToTarget = Mathf.Atan2((player.transform.position.x - transform.position.x), (player.transform.position.z - transform.position.z)) * Mathf.Rad2Deg; transform.eulerAngles = new Vector3(0, angleToTarget, 0); if (Vector3.Distance(transform.position, player.transform.position) > 2) { transform.position = Vector3.MoveTowards(transform.position, player.transform.position, RunSpeed * Time.deltaTime); } bool canDealDamage = timeSinceLastAttack > 1 / AttacksPerSecond ? true : false; if (canDealDamage) { timeSinceLastAttack = 0; PlayerHealth php = player.GetComponent <PlayerHealth>(); if (php == null) { Debug.Log("No player health"); } DealDamage(php); canDealDamage = false; } } } }