Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help convert Javascript To C#

Discussion in 'Scripting' started by Jorjor210, May 27, 2015.

  1. Jorjor210

    Jorjor210

    Joined:
    May 3, 2015
    Posts:
    91
    I'm currently in the process of converting this javascript to C# (This is only part of code, hence Random.Range 1,22) but I keep getting the error "error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected" What exactly is wrong about this code? I'm not exactly good at converting yet, So please be kind. The error occurs at the if statement

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Spawn20 : MonoBehaviour {
    5.  
    6.     public GameObject cube;
    7.     public GameObject warning;
    8.     public int spawn_position;
    9.         public static int num;
    10.  
    11. void Update () {
    12.             num = Random.Range(1,22);
    13.      
    14.         //1
    15.         if (num ==1) {
    16.             spawn_position = Vector3(-9.78,0,0);
    17.             int temp_spawn_cube = Instantiate(cube, spawn_position, Quaternion.identity);
    18.          
    19.         }
     
  2. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    You need to add the 'new' keyword to your Vector3 constructor
    Code (CSharp):
    1. spawn_position =  new Vector3(-9.78,0,0);
     
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,256
    As well as above post.

    Should be
    Code (CSharp):
    1. Vector3 spawn_position;
    Doesn't need to be static.

    Should be

    Code (CSharp):
    1. GameObject temp_spawn_cube = [URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Instantiate']Instantiate[/URL](cube, spawn_position, [URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Quaternion']Quaternion[/URL].[URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=identity']identity[/URL]);
     
    DoomSamurai likes this.
  4. DoomSamurai

    DoomSamurai

    Joined:
    Oct 10, 2012
    Posts:
    159
    Lol my eyes caught one issue and my brain just stopped there