I
I
its_a_me_mario2020-11-08 15:27:45
C++ / C#
its_a_me_mario, 2020-11-08 15:27:45

How to bind RigidBody to a script?

5fa7e33f39d61457271225.png

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

public class Rocket : MonoBehaviour
{
Rigidbody rigidBody;
    void Start()
    {
        rigidBody = GetComponent<Rigidbody>();
    }

    void Update()
        {
            processInput();
        }
    void processInput()
        {
            if(Input.GetKey(KeyCode.Space))
            {
                rigidBody.AddRelativeForce(Vector3.up);
                print("пробел");
            }
            if(Input.GetKey(KeyCode.A))
            {
                print("Поворот влево");
            }
            else if(Input.GetKey(KeyCode.D))
            {
                print("Поворот вправо");
            }
        }
}

In the screenshot in line 7, rigidBody lights up white, although it should light up blue, judging by the tutorial.
While writing, it lights up blue, but when I put a semicolon, it starts burning white.
RigidBody and script on the same object in the unit.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-11-08
@its_a_me_mario

In the screenshot in line 7, rigidBody lights up white, although it should light up blue, judging by the tutorial.

Change the theme of the vizhla - it will burn at least red)))
And he "connects" you at the start.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question