Inheritance: MonoBehaviour
示例#1
0
    private void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            // Do a raycast to find our selected tile
            Camera  mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
            Vector2 position   = mainCamera.ScreenToWorldPoint(Input.mousePosition);

            RaycastHit2D hit = Physics2D.Raycast(position, Vector2.zero, 0);
            if (hit)
            {
                StrategyTile tile = hit.collider.gameObject.GetComponent <StrategyTile>();
                tile.NumberOfClicks++;

                StringBuilder info = new StringBuilder();
                info.AppendFormat("Tile: {0}", tile.TileType);
                info.AppendLine();
                info.Append(tile.TileNote);
                info.AppendLine();
                info.AppendFormat("Clicks: {0}", tile.NumberOfClicks);
                this.uiText.text = info.ToString();
            }
            else
            {
                this.uiText.text = "No tile selected";
            }

            // Place the cursor
            GameObject cursor = GameObject.FindGameObjectWithTag("Cursor");
            position.x -= position.x % 16;
            position.y -= position.y % 16;
            cursor.transform.position = position;
        }
    }
示例#2
0
 public void HandleCustomProperties(GameObject gameObject,
                                    IDictionary <string, string> customProperties)
 {
     if (customProperties.ContainsKey("Terrain"))
     {
         // Add the terrain tile game object
         StrategyTile tile = gameObject.AddComponent <StrategyTile>();
         tile.TileType = customProperties["Terrain"];
         tile.TileNote = customProperties["Note"];
     }
 }