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. Dismiss Notice

object does not move

Discussion in 'Scripting' started by FireJojoBoy, Apr 14, 2020.

  1. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    here is the script omg pls halp:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class safetyCar : MonoBehaviour
    5. {
    6.     public GameObject player;
    7.     public Animator anim;
    8.     public Vector2 NoDriveTime;
    9.     public AudioSource Sirene;
    10.     private Rigidbody2D rb;
    11.     void Start()
    12.     {
    13.         Invoke("Drive", 1);
    14.     }
    15.     private void FixedUpdate()
    16.     {
    17.         transform.position = new Vector3(0, player.transform.position.y - 7, 0);
    18.     }
    19.     public void Drive()
    20.     {
    21.         if(player.GetComponent<Player>().RouteLength > 2000)
    22.         {
    23.             Sirene.Play();
    24.             anim.SetBool("drives", true);
    25.             Invoke("driven", 5);
    26.         }
    27.         Invoke("Drive", Random.Range(NoDriveTime.x, NoDriveTime.y));
    28.     }
    29.     public void driven()
    30.     {
    31.         anim.SetBool("drives", false);
    32.     }
    33. }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    This script will only move the object it is attached to if the "player" object is moving on the y axis from some other source. Is that happening?
     
  3. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    yes! the player is moving