Stepping on game object moves quickly to react
I have floors that get instantiated, the floors are randomly moved based on tiles location.
Example: Tile (44) the Floor moved to Tile (44) after 2 sec. the Floor moves to another random tile, Tile (235) etc.
The issue is that when the player lands on the floor the floor is suppose to remain in place where the user hits the floor. The floor move to another location to quickly to remain in the location. I am using the Void Update.
See Sample Code Below:
public class RandomFloors : MonoBehaviour
void Update() { //--Method 1 to loop create loop trap floor--//
timesub -= Time.deltaTime; if (timesub <= 0) {
randomNumber = Random.Range(7, 678);
trapFloor = GameObject.Find("Floor (" + trapAmount.ToString() + ")");
randomNumberLocation[trapAmount] = randomNumberLocation[trapAmount] == -1 ? -1: randomNumber;
if (trapFloor != null)
{
var floorNumber = "Tile (" + randomNumber.ToString() + ")";
floorBase = GameObject.Find(floorNumber).transform;
trapFloor.transform.position = floorBase.transform.position;
}
trapAmount++;
if (trapAmount == maxTrapAmount)
{
trapAmount = 0;
}
timesub = timer;
}
//--Method 1 end--//
}
public class FloorTrap : MonoBehaviour
void OnTriggerEnter2D(Collider2D collision) { if(collision.tag == "Player") { if (RandomFloors.instance.trapFloor.name.Contains("Floor")) {
RandomFloors.instance.trapFloor.name = RandomFloors.instance.trapFloor.name.Replace("Floor", "Pressed");
}
}
}
The above code works to change the name of the object, but the object already moved to the next random location.
Thanks
Your answer
Follow this Question
Related Questions
How to move an object on a moving platform with the platform 0 Answers
Moving slowly copy of object to random position on x,z? 0 Answers
Unity 2D jump "fly" 0 Answers
Player loses momentum when landing 0 Answers