Answers for "unity requirecomponent"

C#
6

require component unity

// PlayerScript requires the GameObject to have a Rigidbody component
[RequireComponent(typeof(Rigidbody))]
public class PlayerScript : MonoBehaviour
{
...
Posted by: Guest on January-09-2021
13

unity requirecomponent

using UnityEngine;// PlayerScript requires the GameObject to have a Rigidbody component
[RequireComponent(typeof(Rigidbody))]
public class PlayerScript : MonoBehaviour
{
    Rigidbody rb;    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }    void FixedUpdate()
    {
        rb.AddForce(Vector3.up);
    }
}
Posted by: Guest on January-29-2020

C# Answers by Framework

Browse Popular Code Answers by Language