全部回复(2)

  • akitutu 楼主 1 楼

    void Update () { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if(Physics.Raycast(ray, out hit,1000)) { if(hit.collider.tag=="Ground") { // Debug.Log("hit colllider"); print("hit collider"); } } } 报错是: NullReferenceException: Object reference not set to an instance of an object GameController.Update () (at Assets/Scripts/GameController.cs:15)
  • akitutu 楼主 2 楼

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class GameController : MonoBehaviour {
    
    
        // Use this for initialization
        void Start () {
    		
    	}
    	
    	// Update is called once per frame
    	void Update () {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if(Physics.Raycast(ray, out hit,1000))
                {
                if(hit.collider.tag=="Ground")
                {
                    // Debug.Log("hit colllider");
                    print("hit collider");
                }
            }
    	}
    }
    

     

发表回复

登录后可以回复