Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my problem in line 9

error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer Unity C#

What I have tried:

public GameObject camera;
public Material skybox;
void Start () {
    if (File.Exists (Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "backgroundimage.txt")))
    {
        Camera cam = camera.GetComponent<Camera> ();
        cam.clearFlags = CameraClearFlags.Skybox;
        StreamReader reader = new StreamReader((Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "backgroundimage.txt")));
        skybox.SetTexture = reader.ReadLine();
        cam.GetComponent<Skybox> ().material = skybox;
    }
    else
    {
        Camera cam = camera.GetComponent<Camera> ();
        cam.clearFlags = CameraClearFlags.SolidColor;
    }
Posted
Updated 6-Dec-19 21:20pm

1 solution

Look at the error message, it tells you what the problem is, and where.
So look at line 9 (CTRL+g will take you there in VS) and it is an assignment:
skybox.SetTexture = reader.ReadLine();
The name SetTexture implies a method to me, and you can't assign to a method.

So look at the documentation (a simple Google will get you there): Unity - Scripting API: Material.SetTexture[^]
Yes, it's a method. So you need to call it, and pass it two parameters:
skybox.SetTexture(reader.ReadLine, ???);
(Or similar) - and provide it with the Texture to set it to, replacing the "???" in my example.
 
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