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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

error cso411 help pls

Discussion in 'Scripting' started by C05M1C, Jul 15, 2018.

  1. C05M1C

    C05M1C

    Joined:
    Sep 18, 2017
    Posts:
    3
    i got this error while following a totorial, here is my code
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. public class PlayerController : NetworkBehaviour
    5. {
    6.     void Update()
    7.     {
    8.         if (!isLocalPlayer)
    9.         {
    10.             return;
    11.         }
    12.  
    13.         var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
    14.         var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
    15.  
    16.         transform.Rotate(0, x, 0);
    17.         transform.Translate(0, 0, z);
    18.     }
    19.  
    20.     public override void OnStartLocalPlayer()
    21.     {
    22.         GetComponent().material.color = Color.blue;
    23.     }
    24.  
    25. }
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hi C05M1C,

    It is good that you have supplied code and used code tags. But do try to include as much information as possible. For example, what was the exact, and full, error message (including line numbers). :)

    However, in this case, it looks like line 22 causing the problem. You need to specify the type of component you are wanting to access the material of. For example, maybe something like this :
    GetComponent<MeshRenderer>().material.color = Color.blue;
    .