Hi everyone, I’m trying to make a script that moves a gameobject to a point determined by an int array . I keep getting this error from the console saying I can’t implicitly convert float to vector3 . Any idea what is wrong with my code?
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
public int[] someIntArray;
void Awake(){
someIntArray = new int[]{1,2,3,4};
}
void OnGUI() {
for (int i= 0; i < someIntArray.Length; i++){
if (GUI.Button(new Rect(10, 20, 100, 20),someIntArray*.ToString())){*
transform.position = transform.position*;*
* }*
* }*
}
Because [transform.position][1] is a Vector3, and you’re trying to set it to an int. You could add a Vector3 array, and be sure to either set the positions on Awake or Start, or set in the inspector since the array is public. Doing something like this would work:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public Vector3[] someVector3Array;
public int[] someIntArray;
void Start()
{
someIntArray = new int[]
{
1, 2, 3, 4
};
someVector3Array = new Vector3[]
{
new Vector3(0, 0, 0),
new Vector3(0, 10, 0),
new Vector3(0, 20, 0),
new Vector3(0, 30, 0)
};
}
void OnGUI()
{
for (int i= 0; i < someIntArray.Length; i++)
{
if (GUILayout.Button(someIntArray*.ToString()))*
_ transform.position = someVector3Array*;_
_ }_
_ }*_
* GUILayout.Label("Position = "+transform.position);*
}
}
_*[1]:http://docs.unity3d.com/Documentation/ScriptReference/Transform-position.html*_