- Home /
What's wrong with my code? c# tower defense
I'm trying to create a tower defense game. I made one in javascript & in java but never one in c#. I thought I could just spawn wall objects to create the ground then create a path after all the tiles where walls, but so far It says i'm trying to turn a double into a float. I totally don't see where it would think that. I'm using vector3, a for loop & a GameObject. I want all the walls to spawn where I enter the game, so I can get to modifying them. Here the code: using UnityEngine;
public class createWalls : MonoBehaviour
{
public GameObject wall;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 10; i++){
Vector3 p = new Vector3(i,1,-4.5);
GameObject a = Instantiate(wall,p,Quaternion.identity);
}
}
}
Answer by RaptorRush · Sep 05, 2020 at 01:56 AM
The Vector3 constructor is expecting 3 floats, in c# all floats must contain an “f” suffix, otherwise is interpreted as a double.
Vector3 p = new Vector3(i, 1, -4.5f);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how to sort a list of gameobjects? 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
detect target using variable 0 Answers