Search Unity

Error in RigidBody

Discussion in 'Scripting' started by vidit0210, Apr 3, 2016.

  1. vidit0210

    vidit0210

    Joined:
    Dec 30, 2015
    Posts:
    30
    This is the Code:

    The code is From unity networking Tutorials.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. public class PlayerController : NetworkBehaviour
    5. {
    6.     public GameObject bulletPrefab;
    7.     public Transform bulletSpawn;
    8.  
    9.  
    10.     void Update()
    11.     {
    12.        
    13.         if (!isLocalPlayer)
    14.         {
    15.             return;
    16.         }
    17.  
    18.         var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
    19.         var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
    20.  
    21.         transform.Rotate(0, x, 0);
    22.         transform.Translate(0, 0, z);
    23.  
    24.         if (Input.GetKeyDown(KeyCode.Space))
    25.         {
    26.             Fire();
    27.         }
    28.     }
    29.  
    30.  
    31.     void Fire()
    32.     {
    33.         // Create the Bullet from the Bullet Prefab
    34.         var bullet = (GameObject)Instantiate(
    35.             bulletPrefab,
    36.             bulletSpawn.position,
    37.             bulletSpawn.rotation);
    38.  
    39.         // Add velocity to the bullet
    40.         bullet.GetComponent<RigidBody>().velocity = bullet.transform.forward * 6;
    41.  
    42.         // Destroy the bullet after 2 seconds
    43.         Destroy(bullet, 2.0f);      
    44.     }
    45.  
    46.     public override void OnStartLocalPlayer ()
    47.     {
    48.         GetComponent<MeshRenderer>().material.color = Color.blue;
    49.     }
    50. }
    51.  
    Error:Assets/Scripts/PlayerController.cs(40,37): error CS0246: The type or namespace name `RigidBody' could not be found. Are you missing a using directive or an assembly reference?​
     
  2. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    I had the same error when trying simple script aswell. Code completion wouldn't even find Vector2. Close Visual Studio and reopen the script, it propably links the project right that time. At least for me it did.
     
  3. jaasso

    jaasso

    Joined:
    Jun 19, 2013
    Posts:
    64
    i think you need to type Rigidbody, not RigidBody with a capital B
     
    UNDRAGONCOLORADO and vidit0210 like this.
  4. sahmedrb

    sahmedrb

    Joined:
    Jul 15, 2022
    Posts:
    1
    thanks that helped I think the tutorials were outdated