Jump to content
Unity Insider Forum

Kaan38

Members
  • Posts

    6
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Kaan38's Achievements

Newbie

Newbie (1/3)

0

Reputation

  1. Hab den Fehler gefunden im Grid war die Shape Storage nicht mehr drinnen 😅. Hab anscheinend vergessen zu speichern...
  2. Die Codes sind zwar noch da aber was in Unity war ist weg. Das Video hatte ich aufgenommen als ich fertig war. Und Screenshot ist von jetzt. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Grid : MonoBehaviour { public ShapeStorage shapeStorage; public int columns = 0; public int rows = 0; public float squaresGap = 0.1f; public GameObject gridSquare; public Vector2 startPosition = new Vector2(0.0f, 0.0f); public float squareScale = 0.5f; public float everySquareOffset = 0.0f; private Vector2 _offset = new Vector2(0.0f, 0.0f); private List<GameObject> _gridSquares = new List<GameObject>(); private void OnEnable() { GameEvents.CheckIfShapeCanBePlaced += CheckIfShapeCanBePlaced; } private void OnDisable() { GameEvents.CheckIfShapeCanBePlaced -= CheckIfShapeCanBePlaced; } void Start() { CreateGrid(); } private void CreateGrid() { SpawnGridSquares(); SetGridSquarePositions(); } private void SpawnGridSquares() { //0, 1, 2, 3, 4, //5, 6, 7, 8, 9 int square_index = 0; for (var row = 0; row < rows; ++row) { for (var column = 0; column < columns; ++column) { _gridSquares.Add(Instantiate(gridSquare) as GameObject); _gridSquares[_gridSquares.Count -1].GetComponent<GridSquare>().SquareIndex = square_index; _gridSquares[_gridSquares.Count -1].transform.SetParent(this.transform); _gridSquares[_gridSquares.Count -1].transform.localScale = new Vector3(squareScale, squareScale, squareScale); _gridSquares[_gridSquares.Count -1].GetComponent<GridSquare>().SetImage(square_index % 2 == 0); square_index++; } } } private void SetGridSquarePositions() { int column_number = 0; int row_number = 0; Vector2 square_gap_number = new Vector2(0.0f, 0.0f); bool row_moved = false; var square_rect = _gridSquares[0].GetComponent<RectTransform>(); _offset.x = square_rect.rect.width * square_rect.transform.localScale.x + everySquareOffset; _offset.y = square_rect.rect.height * square_rect.transform.localScale.y + everySquareOffset; foreach (GameObject square in _gridSquares) { if (column_number + 1 > columns) { square_gap_number.x = 0; //go to the next column column_number = 0; row_number++; row_moved = false; } var pos_x_offset = _offset.x * column_number + (square_gap_number.x * squaresGap); var pos_y_offset = _offset.y * row_number + (square_gap_number.y * squaresGap); if (column_number > 0 && column_number % 3 == 0) { square_gap_number.x++; pos_x_offset += squaresGap; } if (row_number > 0 && row_number % 3 == 0 && row_moved == false) { row_moved = true; square_gap_number.y++; pos_y_offset += squaresGap; } square.GetComponent<RectTransform>().anchoredPosition = new Vector2(startPosition.x + pos_x_offset, startPosition.y - pos_y_offset); square.GetComponent<RectTransform>().localPosition = new Vector3(startPosition.x + pos_x_offset, startPosition.y - pos_y_offset, 0.0f); column_number++; } } private void CheckIfShapeCanBePlaced() { var squareIndexes = new List<int>(); foreach (var square in _gridSquares) { var gridSquare = square.GetComponent<GridSquare>(); if (gridSquare.Selected && !gridSquare.SquareOccupied) { squareIndexes.Add(gridSquare.SquareIndex); gridSquare.Selected = false; //gridSquare.ActivateSquare(); } } var currentSelectedShape = shapeStorage.GetcurrentSelectedShape(); if (currentSelectedShape == null) return; //there is no selected Shape. if (currentSelectedShape.TotalSquareNumber == squareIndexes.Count) { foreach (var SquareIndex in squareIndexes) { _gridSquares[SquareIndex].GetComponent<GridSquare>().PlaceShapeOnBoard(); } currentSelectedShape.DeactiveateShape(); } else { GameEvents.MoveShapeToStartPosition(); } } } filtered-DF7E50CD-A477-4B53-BCB9-DBDFD5DC2D3F.mov
  3. Servus, ich hab meine Codes fertig geschrieben, gespeichert und in Unity getestet alles perfekt. Habs heute wieder aufgemacht um weiter zu machen bevor ich eine Zeile Code geschrieben hab wieder reingeschaut alles ist verloren aber Codes sind noch da und ich bekomme diese Fehler. Kann mir jemand sagen woher das kommt? NullReferenceException: Object reference not set to an instance of an object Grid.CheckIfShapeCanBePlaced () (at Assets/Scripts/Game/Grid/Grid.cs:128) Shape.OnEndDrag (UnityEngine.EventSystems.PointerEventData eventData) (at Assets/Scripts/Shape/Shape.cs:288) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IEndDragHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:85) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272) UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)
  4. Servus, ich wollte einen Drawer für mein Spiel machen aber ich bekomme gerade 19 mal so eine ähnliche Meldung. Könnte mir jemand Helfen? Assets/Scripts/Editor/ShapeDataDrawer.cs(24,31): error CS1061: 'ShapeData' does not contain a definition for 'board' and no accessible extension method 'board' accepting a first argument of type 'ShapeData' could be found (are you missing a using directive or an assembly reference?) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; [CustomEditor(typeof(ShapeData), false)] [CanEditMultipleObjects] [System.Serializable] public class ShapeData : Editor { private ShapeData ShapeDataInstance => target as ShapeData; public override void OnInspectorGUI() { serializedObject.Update(); ClearBoardButton(); EditorGUILayout.Space(); DrawColumnsInputFields(); EditorGUILayout.Space(); if (ShapeDataInstance.board != null && ShapeDataInstance.columns > 0 && ShapeDataInstance.rows > 0) { DrawBoardTable(); } serializedObject.ApplyModifiedProperties(); if (GUI.changed) { EditorUtility.SetDirty(ShapeDataInstance); } } private void ClearBoardButton() { if (GUILayout.Button("Clear Board")) { ShapeDataInstance.Clear(); } } private void DrawColumnsInputFields() { var columnsTemp = ShapeDataInstance.columns; var rowsTemp = ShapeDataInstance.rows; ShapeDataInstance.columns = EditorGUILayout.IntField("Columns", ShapeDataInstance.columns); ShapeDataInstance.rows = EditorGUILayout.IntField("Rows", ShapeDataInstance.rows); if ((ShapeDataInstance.columns != columnsTemp || ShapeDataInstance.rows != rowsTemp) && ShapeDataInstance.columns > 0 && ShapeDataInstance.rows > 0) { ShapeDataInstance.CreateNewBoard(); } } private void DrawBoardTable() { var tableStyle = new GUIStyle("box"); tableStyle.padding = new RectOffset(10, 10, 10, 10); tableStyle.margin.left = 32; var headerColumnStyle = new GUIStyle(); headerColumnStyle.fixedWidth = 65; headerColumnStyle.alignment = TextAnchor.MiddleCenter; var rowStyle = new GUIStyle(); rowStyle.fixedHeight = 25; rowStyle.alignment = TextAnchor.MiddleCenter; var dataFieldStyle = new GUIStyle(EditorStyles.miniButtonMid); dataFieldStyle.normal.background = Texture2D.grayTexture; dataFieldStyle.onNormal.background = Texture2D.whiteTexture; for (var row = 0; row < ShapeDataInstance.rows; row++) { EditorGUILayout.BeginHorizontal(headerColumnStyle); for (var column = 0; column < ShapeDataInstance.columns; column++) { EditorGUILayout.BeginHorizontal(rowStyle); var data = EditorGUILayout.Toggle(ShapeDataInstance.board[row].column[column], dataFieldStyle); ShapeDataInstance.board[row].column[column] = data; EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndHorizontal(); } } }
  5. HAHAHAHA ich hab das erst eben gemerkt. Hab einfach loacl geschrieben. Danke nochmals😄
  6. Hallo, ich habe seit gestern mit Unity angefangen und wollte ein Block Doku spiel machen. Problem ist nur, vom Script werden die Variablen für das Grid und GridSquare in Unity nicht angezeigt. Ich bekomme folgende Fehlermeldung. Assets/Scripts/Game/Grid/Grid.cs(90,50): error CS1061: 'RectTransform' does not contain a definition for 'loaclPosition' and no accessible extension method 'loaclPosition' accepting a first argument of type 'RectTransform' could be found (are you missing a using directive or an assembly reference?) using System.Collections; using System.Collections.Generic; using UnityEngine; public class Grid : MonoBehaviour { public int columns = 0; public int rows = 0; public float squaresGap = 0.1f; public GameObject gridSquare; public Vector2 startPosition = new Vector2(0.0f, 0.0f); public float squareScale = 0.5f; public float everySquareOffset = 0.0f; private Vector2 _offset = new Vector2(0.0f, 0.0f); private List<GameObject> _gridSquares = new List<GameObject>(); void Start() { CreateGrid(); } private void CreateGrid() { SpawnGridSquares(); SetGridSquarePositions(); } private void SpawnGridSquares() { //0, 1, 2, 3, 4, //5, 6, 7, 8, 9 int square_index = 0; for (var row = 0; row < rows; ++row) { for (var column = 0; column < columns; ++column) { _gridSquares.Add(Instantiate(gridSquare) as GameObject); _gridSquares[_gridSquares.Count -1].transform.SetParent(this.transform); _gridSquares[_gridSquares.Count -1].transform.localScale = new Vector3(squareScale, squareScale, squareScale); _gridSquares[_gridSquares.Count -1].GetComponent<GridSquare>().SetImage(square_index % 2 == 0); square_index++; } } } private void SetGridSquarePositions() { int column_number = 0; int row_number = 0; Vector2 square_gap_number = new Vector2(0.0f, 0.0f); bool row_moved = false; var square_rect = _gridSquares[0].GetComponent<RectTransform>(); _offset.x = square_rect.rect.width * square_rect.transform.localScale.x + everySquareOffset; _offset.y = square_rect.rect.height * square_rect.transform.localScale.y + everySquareOffset; foreach (GameObject square in _gridSquares) { if (column_number + 1 > columns) { square_gap_number.x = 0; //go to the next column column_number = 0; row_number++; row_moved = false; } var pos_x_offset = _offset.x * column_number + (square_gap_number.x * squaresGap); var pos_y_offset = _offset.y * row_number + (square_gap_number.y * squaresGap); if (column_number > 0 && column_number % 3 == 0) { square_gap_number.x++; pos_x_offset += squaresGap; } if (row_number > 0 && row_number % 3 == 0 && row_moved == false) { row_moved = true; square_gap_number.y++; pos_y_offset += squaresGap; } square.GetComponent<RectTransform>().anchoredPosition = new Vector2(startPosition.x + pos_x_offset, startPosition.y - pos_y_offset); square.GetComponent<RectTransform>().loaclPosition = new Vector3(startPosition.x + pos_x_offset, startPosition.y - pos_y_offset, 0.0f); } } }
×
×
  • Create New...