void FixedUpdate() { // get movement magnitudes float horizMag = Input.GetAxis("Horizontal"); float verticalMag = Input.GetAxis("Vertical"); Vector2 movement = new Vector2(horizMag, verticalMag); // check if the player is in a box bool inBox = gameObject.GetComponent <PlayerBox>().inBox; float trueSpeed = speed; // player moves slower if they're in a box if (inBox) { trueSpeed *= 0.7f; } // player moves faster if they have the running shoes item if (PlayerItems.HasItem("RunningShoes")) { trueSpeed *= 1.2f; } // move the player through rigidbody forces rb2d.AddForce(movement * trueSpeed); }
private void Start() { if (PlayerItems.HasItem(itemName)) { // player already has this item, destroy it Destroy(gameObject); } }
void Start() { // initialise LineRenderer lineRenderer = gameObject.AddComponent <LineRenderer>(); lineRenderer.material = new Material(Shader.Find("Sprites/Default")); lineRenderer.widthMultiplier = 0.05f; lineRenderer.positionCount = segments; lineRenderer.loop = true; // find player components GameObject player = GameObject.FindWithTag("Player"); playerMovement = player.GetComponent <PlayerMovement>(); playerBox = player.GetComponent <PlayerBox>(); // reduce search distance if this guard is in the dark // and the player has found the cloak item if (inDarkArea && PlayerItems.HasItem("Cloak")) { baseSearchDist /= 2f; } }