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

how do I fix this bug in my code "The name 'chessBoard' does not exist in the current context" even though it does exist in the contex?

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class pawn_movement : MonoBehaviour { Vector2 startpos; private bool isDragging; private float moves = 0; private float differentmoves; private int precol; private int prerow; private int col; private int row; public bool Initializedcheck = false; public void OnMouseDown() { differentmoves = 0; startpos = transform.position; isDragging = true; } public void OnMouseUp() { isDragging = false; Vector2 pos = transform.position; pos.x = Mathf.Round(pos.x); pos.y = Mathf.Round(pos.y); transform.position = pos; if ( transform.position.x < -.5 || transform.position.x > 7.5 || transform.position.y < -.5 || transform.position.y > 7.5) { transform.position = startpos; } if (moves == 0 && transform.position.y-startpos.y > 0.5 && transform.position.y-startpos.y <= 2.5 && transform.position.x-startpos.x < 0.5 && transform.position.x-startpos.x > -0.5) { moves += 1; differentmoves = 1; if (Initializedcheck == false) { ChessBoard chessBoard = new ChessBoard(); precol = (int)Mathf.Round(startpos.x); prerow = (int)Mathf.Round(startpos.y); col = (int)Mathf.Round(transform.position.x); row = (int)Mathf.Round(transform.position.y); chessBoard.MovePiece(prerow, precol, row, col); Initializedcheck = true; } else { precol = (int)Mathf.Round(startpos.x); prerow = (int)Mathf.Round(startpos.y); col = (int)Mathf.Round(transform.position.x); row = (int)Mathf.Round(transform.position.y); **chessBoard**.MovePiece(prerow, precol, row, col); } } else if (differentmoves == 0 && transform.position.y-startpos.y > 0.5 && transform.position.y-startpos.y < 1.5 && transform.position.x-startpos.x < 0.5 && transform.position.x-startpos.x > -0.5) { if (Initializedcheck == false) { ChessBoard chessBoard = new ChessBoard(); precol = (int)Mathf.Round(startpos.x); prerow = (int)Mathf.Round(startpos.y); col = (int)Mathf.Round(transform.position.x); row = (int)Mathf.Round(transform.position.y); chessBoard.MovePiece(prerow, precol, row, col); Initializedcheck = true; } else { precol = (int)Mathf.Round(startpos.x); prerow = (int)Mathf.Round(startpos.y); col = (int)Mathf.Round(transform.position.x); row = (int)Mathf.Round(transform.position.y); **chessBoard**.MovePiece(prerow, precol, row, col); } } else { transform.position = startpos; } } void Update() { if (isDragging) { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; transform.Translate(mousePosition); } } } The two chessBoard variables that I put asterisks around cause the error in the title, even though there is no way for it to not exist in the context. I'm stumped on how to fix this so I could use some help.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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