- Home /
Question by
huberthetman9 · Mar 19, 2020 at 01:45 PM ·
rigidbodytransformvector3velocity
Animation or smooth teleportation
I am starting in unity, my problem is that I would like to smoothly drive the car and not teleportation here is my code .. and sorry for my English
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DrivePost : MonoBehaviour { public Transform Location1;
public Transform player;
public float czekaj = 50f;
public float odliczanieczasu = 50f;
public GUISkin skin;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 12f;
}
// Update is called once per frame
void Update()
{
odliczanieczasu += Time.deltaTime;
if (odliczanieczasu >= czekaj)
{
Debug.Log("OdliczanieCzasuWykonane");
odliczanieczasu = 0f;
Time.timeScale = 16;
}
if (Input.GetKey(KeyCode.W))
{
}
else
{
transform.rotation = Quaternion.Euler(0, 90, 0);
transform.Translate(Vector3.forward * Time.deltaTime);
}
}
void OnGUI()
{
GUI.skin = skin;
if (GUI.Button(new Rect(10, 10, 1000, 1000),""))
{
if (transform.position.z > 8 && transform.position.z < 11)
{
transform.Translate(new Vector3(-8f, 0, 0));
}
if (transform.position.z > -1 && transform.position.z < 4)
{
transform.Translate(new Vector3(-8f, 0, 0));
}
}
if (GUI.Button(new Rect(1000, 10, 1000, 1000), ""))
{
if (transform.position.z > 8 && transform.position.z < 11)
{
transform.Translate(new Vector3(8, 0, 0));
}
if (transform.position.z > 15 && transform.position.z < 20)
{
transform.Translate(new Vector3(8, 0, 0));
}
}
}
void OnTriggerEnter(Collider other)
{
Debug.Log("Kolizja");
player.transform.position = Location1.position;
print(transform.position.x);
Time.timeScale = 12f;
}
}
Comment