Help with Script js -> c#

Hi
I’m pretty poor in scripting :confused:
I just want to “convert” a js into c# script.

Firstly, my original js script:

var startPoint: Vector3;
var endPoint: Vector3;
var numObjects: int;
var objects: Transform[];
var Road: GameObject;


function Start() {


	for (i = 0; i < numObjects; i++) {
		var newObj = Instantiate(objects[Random.Range(0, objects.Length)]);
		newObj.position = Vector3.Lerp(startPoint, endPoint, (i * 1.0) / (numObjects - 1));
		newObj.transform.LookAt(endPoint);
		newObj.transform.localEulerAngles.y=270;
		
	}
}

and now what I tried in c#:

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


	
	public void Start() {
	
		public Vector3 startPoint;
		public Vector3 endPoint;
		public int numObjects;
		public Transform[] objects;
		public GameObject Road;


		for (i = 0; i < numObjects; i++) {
			var newObj = Instantiate(objects[Random.Range(0, objects.Length)]);
			newObj.position = Vector3.Lerp(startPoint, endPoint, (i * 1.0) / (numObjects - 1));
			newObj.transform.LookAt(endPoint);
			newObj.transform.localEulerAngles.y=270;
		}
	}

I get the Error CS1525: Unexpected symbol ‘public’

I want to be able to drag and drop objects into the transform field, so I can’t delete the ‘public’, right?
Or is it different in C#?

Please help :frowning:

You are missing the class head:

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


public class YourClassNameWhichEqualsYourScriptName : MonoBehaviour
{
 .. // everything else
}

Edit: Oh and your for is not functional, you need to specify the type if I before using it:

for (int i = 0; i < numObjects; i++) {

or

for (var i = 0; i < numObjects; i++) {

Also you need to cast the return value of Instantiate to GameObject:

var newObj = (GameObject)Instantiate(objects[Random.Range(0, objects.Length)]);