using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManger : MonoBehaviour {
private BoxCollider2D rightWall;
private BoxCollider2D leftWall;
private BoxCollider2D upWall;
private BoxCollider2D downWall;
// Use this for initialization
void Start () {
ResetWall();
}
// Update is called once per frame
void Update () {
}
void ResetWall()
{
rightWall = transform.Find("rightWall").GetComponent<BoxCollider2D>();
leftWall = transform.Find("leftWall").GetComponent<BoxCollider2D>();
downWall = transform.Find("downWall").GetComponent<BoxCollider2D>();
upWall = transform.Find("upWall").GetComponent<BoxCollider2D>();
Vector3 tempPosition = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));
upWall.transform.position = new Vector3(0, tempPosition.y + 0.5f, 0);
upWall.size = new Vector2(tempPosition.x * 2, 1);
}
}
错误提示:nullReferencEexception:object refrence not set to an instance of object
using System.Collections.Generic;
using UnityEngine;
public class GameManger : MonoBehaviour {
private BoxCollider2D rightWall;
private BoxCollider2D leftWall;
private BoxCollider2D upWall;
private BoxCollider2D downWall;
// Use this for initialization
void Start () {
ResetWall();
}
// Update is called once per frame
void Update () {
}
void ResetWall()
{
rightWall = transform.Find("rightWall").GetComponent<BoxCollider2D>();
leftWall = transform.Find("leftWall").GetComponent<BoxCollider2D>();
downWall = transform.Find("downWall").GetComponent<BoxCollider2D>();
upWall = transform.Find("upWall").GetComponent<BoxCollider2D>();
Vector3 tempPosition = Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));
upWall.transform.position = new Vector3(0, tempPosition.y + 0.5f, 0);
upWall.size = new Vector2(tempPosition.x * 2, 1);
}
}
错误提示:nullReferencEexception:object refrence not set to an instance of object