Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

First Person Controller not moving after changing it's position

Discussion in 'Scripting' started by SgtBossGamer12, Dec 24, 2015.

  1. SgtBossGamer12

    SgtBossGamer12

    Joined:
    Oct 2, 2014
    Posts:
    16
    I'm new to using c# with unity(got a book and have been reading that for a while), and I've been trying to create a script that puts the player back at the start after a certain amount of time, and it does put the player back to the start, but when you try to move, you hear the footstep sounds, but you can't move.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Timer : MonoBehaviour {
    5.     // Use this for initialization
    6.  
    7.     public GameObject PlayerPosition;
    8.     public float CurrentTime = 30.0f;
    9.     public Vector3 PlayerVector = new Vector3(4.0f, 1.5f, 0);
    10.    
    11.  
    12.    
    13.     void Start () {
    14.  
    15.     }
    16.    
    17.     // Update is called once per frame
    18.     void Update () {
    19.         if (Time.time > CurrentTime) {
    20.             PlayerPosition.transform.position = PlayerVector;
    21.  
    22.         }
    23.     }
    24. }
     
  2. Afrodeity

    Afrodeity

    Joined:
    Dec 19, 2015
    Posts:
    12
    Your code locks the position of your player to PlayerVector after a certain point in time. I suppose you'd want to reset your timer after you've set the player back to his original position. The quickest solution would be to add the following short statement inside your if statement, but I urge you to examine alternatives: CurrentTime += Time.time.
     
  3. SgtBossGamer12

    SgtBossGamer12

    Joined:
    Oct 2, 2014
    Posts:
    16
    It worked, thanks!