Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Instantiating a game Object for a hex grid is giving me the error Cannot convert from CustomClass to UnityEngine.Object?

$
0
0
I have two scripts one that generate's a hex map and the other that provides the name and prefab. Within my MapGen script im getting the error -Argument 1: cannot convert from 'NodeType' to 'UnityEngine.Object' (CS1503) (Assembly-CSharp)- Here's the code of the first script using UnityEngine; using System.Collections.Generic; public class NodeMng : MonoBehaviour { public int height; public int width; private float MapSizeY; private float MapSizeX; public GameObject selectedUnit; public GameObject[] hexGridTiles; public NodeType[] nodeTypes; void Start () { mapGeneration(); } public void mapGeneration (){ for (MapSizeY = 0; MapSizeY < height; MapSizeY = MapSizeY + 0.88f) { bool doOffset = false; for(MapSizeX = 0; MapSizeX < width; MapSizeX = MapSizeX + 0.769f ) { float offset = doOffset ? 0.451f : 0f; MapSizeY = MapSizeY + offset; Vector3 spawnPoint = new Vector3(MapSizeX, MapSizeY, 0); var groundNode = (GameObject)Instantiate (nodeTypes [Random.Range (0, nodeTypes.Length)], spawnPoint, Quaternion.identity); groundNode.name = "Hex_" + MapSizeX + "_" + MapSizeY; groundNode.transform.SetParent(transform, true); ClickableTile ct = groundNode.GetComponent(); ct.tileX = MapSizeX; ct.tileY = MapSizeY; ct.map = this; MapSizeY = MapSizeY - offset; doOffset = !doOffset; //! sets to true } } } } And heres the code for the second script using UnityEngine; using System.Collections; [System.Serializable] public class NodeType{ public string name; public GameObject hexGridTiles; } The error is on the following line var groundNode = (GameObject)Instantiate (nodeTypes [Random.Range (0, nodeTypes.Length)], spawnPoint, Quaternion.identity); When I change nodeTypes to hexGridTiles it works perfectly fine but in this case I need it to attach a string Value to each prefab for path-finding down the line so I'm not sure what this error is trying to tell me any help is much appreciated. For clarity here's a screenshot of what I'm talking about ![alt text][1] [1]: /storage/temp/82985-error-1.png

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>