- Home /
I don't can't make this car elevator work
I want to make a car lift but I have no idea how to make it work
This is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarLift : MonoBehaviour
{
public GameObject min;
public GameObject max;
public GameObject[] Car;
int i;
public float liftSpeed = 20f;
Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
public void pointerDownGreen()
{
FindObjectOfType<AudioManager>().Play("carLift");
Debug.Log("DownGreen");
}
public void pointerDownRed()
{
FindObjectOfType<AudioManager>().Play("carLift");
Debug.Log("DownRed");
}
public void pointerUp()
{
FindObjectOfType<AudioManager>().Stop("carLift");
Debug.Log("Up");
}
private void OnTriggerEnter(Collider trigger)
{
foreach (GameObject Cars in Car)
{
if()
{
break;
}
else
{
continue;
}
}
}
}
I want to make that the car stop when it touches GameObject Min or Max but i don't now how to make the car to move up and down
The car should move when you press a button (upBtn and downBtn).
Answer by miguelfrancisco1505 · Apr 03 at 09:23 PM
if you want to make your car go up you could do: rb.velocity = new Vector2(rb.velocity.x, liftSpeed); this one can be used for adding a force and letting it go up, you can do rb.velocity = new Vector2(rb.velocity.x, 0); but if you want to go up a little bit each update and stop whenever you want the bottom one is one way of doing it too
transform.position += new Vector2(0, liftSpeed * Time.fixedDeltaTime);
and also in your onTrigger if statement there is no condition, this gives errors, you could do if(cars.CompareTag("YourTag"))
Your answer
Follow this Question
Related Questions
Change position of an object on a keystroke within a trigger only? 1 Answer
Grabing Objects - Need Help 0 Answers
What is the trigger? 2 Answers
Build and Run is breaking my triggers! 1 Answer
Some problems with triggers? 1 Answer