local scale not working?
hi, i have a script for randomly placing trees in a certain area. it keeps giving me the error: error CS1502: The best overloaded method match for `UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments. i do not know what to do. please help!
public class TreePlacer : MonoBehaviour
{
List<GameObject> treesList = new List<GameObject>();
public GameObject tree1;
public GameObject tree2;
public GameObject tree3;
// Instantiate the prefab somewhere between -10.0 and 10.0 on the x-z plane
void Start()
{
treesList.Add(tree1);
treesList.Add(tree2);
treesList.Add(tree3);
for (int i = 0; i < 10; i++)
{
Vector3 position = new Vector3(Random.Range(-10.0f, 10.0f), 0, Random.Range(-10.0f, 10.0f));
int prefabIndex = UnityEngine.Random.Range(0,3);
GameObject newTree = Instantiate(treesList[prefabIndex], position, Quaternion.Euler(270, 0, 0));
newTree.transform.localscale = new Vector3(0.07, 0.07, 0.07);
}
}
}
Answer by TBART82 · Oct 11, 2017 at 05:48 AM
Yes, be sure to use floats instead of doubles. Also you have a typo. So change:
newTree.transform.localscale = new Vector3(0.07, 0.07, 0.07);
to
newTree.transform.localScale= new Vector3(0.07f, 0.07f, 0.07f);
thanks! i have vs now. we had to reinstall the system
Why did you accept this answer and not @$$anonymous$$axGuernseyIII who answered a day earlier? edit: oh ok I see he missed your case typo
Answer by MaxGuernseyIII · Oct 11, 2017 at 02:01 AM
First. Install Visual Studio and use it to edit your code. The red underlines would have told you what you needed to know and you wouldn't have had to wait for this answer.
Second, the problem is that you are using doubles where floats are required.
Change
new Vector3(0.07, 0.07, 0.07)
to
new Vector3(0.07f, 0.07f, 0.07f)
I have been using notepad because visual studio and mono develop both crash my computer. PS i am very new to unity. but i still get the error: error CS1061: Type UnityEngine.Transform' does not contain a definition for
localscale' and no extension method localscale' of type
UnityEngine.Transform' could be found. Are you missing an assembly reference? im probably missing something obvious
It's localScale
, not localscale
. Variable names are generally usually written in camelCase.
As $$anonymous$$ax said a proper IDE would help you alot with such common typos. VS is crashing your computer? What kind of computer do you use that is able to run Unity but not able to run VS? I've never heard something like that.
Okay. Well. If you can't use an IDE, you should start learning to pay attention to error messages. They typically have the line and character or column number to tell you where, exactly, the problem is. 99% of the time, knowing where a problem is is what you need to know in order to fix that problem.
Your answer
Follow this Question
Related Questions
Trying to replace 2 objects. Destroying assets is not permitted to avoid data loss. 0 Answers
*Solved* Loop instantiating objects causes my Unity Editor to crash 1 Answer
I got Some Error about how to Transform Postiton Enemy where one point can spawn 2 enemies. 1 Answer
Random.range game object destroying itself before reaching destroy position.Please help. 1 Answer