error CS0443

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class treeGen : MonoBehaviour
{
    public GameObject[] thetrees;
    public float xpos;
    public float zpos;
    public float treeNum;

    void Start()
    {
        GameObject[].transform.Rotate(90f, 0f, 0f, Space.Self);
        StartCoroutine(treeGenerator());
    }
    IEnumerator treeGenerator()
    {
        while (treeNum < 10)
        {
            xpos = Random.Range(-7, 8);
            zpos = Random.Range(-9, 9);
            int randomIndex = Random.Range(0, thetrees.Length);
            GameObject clone = Instantiate(thetrees[randomIndex], new Vector3(xpos, 2.211817f, zpos), Quaternion.identity);
            yield return new WaitForSeconds(1f);//waits for one second to spawn
            //Instantiate(thetrees[randomIndex].transform.Rotate(90, 0, 0, Space.Self));
            treeNum += 1;
        }
    }
}

this gives this error:
6699457--768931--upload_2021-1-7_17-25-3.png

plz help me fix this

Not sure what you’re trying to do with this code: GameObject[].transform.Rotate(90f, 0f, 0f, Space.Self);But it’s not valid syntax. What were you trying to do?

i was trying to rotate the objects
6699469--768937--upload_2021-1-7_17-31-18.png
cos it look like this

This code in meant to generate trees

You could do this with a loop, or just rotate the clones inside yourwhile loop around line 25… But why not just fix your prefabs? Your clones are on their sides because your prefabs are on their sides. Just go edit the prefabs in the prefab editor and fix their orientation.

1 Like

6699511--768946--upload_2021-1-7_17-37-9.png
my prefabs are fine when i drag and drop them
and i tried to rotate inside the while loop i also get a error.

You need to get familiar with language syntax and looking up your errors.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

Hmm, I don’t think your code does what you think it does.

This line (24 in the OP) actually instantiates the object:

GameObject clone = Instantiate(thetrees[randomIndex], new Vector3(xpos, 2.211817f, zpos), Quaternion.identity);

if you want to rotate it after it’s been instantiated:

clone.transform.Rotate(new Vector3(90f, 0, 0));
1 Like

ok thank you

1 Like