26 lines
608 B
C#
26 lines
608 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CarMovement : MonoBehaviour
|
|
{
|
|
public float middleX;
|
|
public float roadWidth = 7.5f;
|
|
public float xSpeed =1;
|
|
public float ySpeed = 0.1f;
|
|
void Update()
|
|
{
|
|
MoveX();
|
|
MoveY();
|
|
}
|
|
float a;
|
|
void MoveX(){
|
|
a+= Time.deltaTime * xSpeed;
|
|
transform.position = new Vector3(middleX+ (Mathf.Sin(a) * (roadWidth/2f)), transform.position.y, transform.position.z);
|
|
}
|
|
|
|
void MoveY(){
|
|
transform.Translate(new Vector3(0,0,ySpeed * Time.deltaTime));
|
|
}
|
|
}
|