Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can`t made object move

Discussion in 'Scripting' started by marakasikot, Apr 27, 2023.

  1. marakasikot

    marakasikot

    Joined:
    May 3, 2022
    Posts:
    1
    Hi! I started one little 3d game project, i made script for movement but object (ball) newer moves, i fixed all spelling errors and not unity nor visual studio gives me error, what can i do to make it work?

    there is a code:


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;

    public class PlayerController : MonoBehaviour
    {

    public float moveSpeed;

    float xInput;
    float yInput;

    Rigidbody rb;


    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
    xInput = Input.GetAxis("Horizontal");
    yInput = Input.GetAxis("Vertical");

    if(transform.position.y <= -5f)
    {
    SceneManager.LoadScene(0);
    }

    }

    private void FixedUpdate()
    {
    rb.AddForce(xInput * moveSpeed, 0, yInput * moveSpeed);
    }
    }
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,381