Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyColorScript : MonoBehaviour
{

public GameObject plane;
private MeshRenderer myRenderer;

private void OnClickChangeColor ()
{
myRenderer = plane.GetComponent<meshrenderer>();
myRenderer.enabled = !myRenderer.enabeld;
}

}

"its in C#"

What I have tried:

I have checked capital. and I have tried {
Posted
Updated 29-Sep-20 22:30pm
Comments
Richard MacCutchan 30-Sep-20 5:11am    
A simple spelling error:
myRenderer.enabled = !myRenderer.enabeld;

Reference: Compiler Error CS1061 | Microsoft Docs[^]

Quote:
This error occurs when you try to call a method or access a class member that does not exist.

Example:
C#
// The following example generates CS1061 because TestClass1 does not have a DisplaySomething method. 
// It does have a method that is called WriteSomething.

// cs1061.cs  
public class TestClass1  
{  
    // TestClass1 has one method, called WriteSomething.  
    public void WriteSomething(string s)  
    {  
        System.Console.WriteLine(s);  
    }  
}  
  
public class TestClass2  
{  
    // TestClass2 has one method, called DisplaySomething.  
    public void DisplaySomething(string s)  
    {  
        System.Console.WriteLine(s);  
    }  
}  
  
public class TestTheClasses  
{  
    public static void Main()  
    {  
        TestClass1 tc1 = new TestClass1();  
        TestClass2 tc2 = new TestClass2();  
        // The following call fails because TestClass1 does not have
        // a method called DisplaySomething.  
        tc1.DisplaySomething("Hello");      // CS1061  
  
        // To correct the error, change the method call to either
        // tc1.WriteSomething or tc2.DisplaySomething.  
        tc1.WriteSomething("Hello from TestClass1");  
        tc2.DisplaySomething("Hello from TestClass2");  
    }  
}  

Now, in your case, look at the line error is being raised and assess.


You need to learn and make use of DEBUGGER. Following will help you learn about it:
Tutorial: Debug Visual Basic code - Visual Studio | Microsoft Docs[^]
First look at the debugger - Visual Studio | Microsoft Docs[^]
 
Share this answer
 
Quote:
C#
myRenderer.enabled = !myRenderer.enabeld;
Two things:

1) C# is case-sensitive. Assuming the class you're referencing follows the standard naming guidelines, the property is most likely called Enabled, not enabled.

2) It's highly unlikely that the class will contain two bool properties called enabled and enabeld. Correct the typo so that you're using the correct property name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900