第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

提示Object reference not set to an instance of an object。未將對象引用設(shè)置到對象的實例 怎么搞啊

using UnityEngine;

using System.Collections;


public class Player : MonoBehaviour

{

public ?GameObject ? mClickEffectPrefab;

public ?GameObject ? mClickEffect;

public float walkSpeed = 2f;

public Light light;

public MovementMotor movement;

private Vector3[] mPath;

private bool bWalking = false;

private int mPathIndex = 0;


// Use this for initialization

void Start ()

{

GameObject.Find ("Main Camera").GetComponent<SceneCamera> ().player = this.gameObject;

}

// Update is called once per frame

void Update ()

{

// Debug.Log ("Horizontal value: " + Input.GetAxis ("Horizontal"));

Vector3 direction = Input.GetAxis ("Horizontal") * transform.right +?

Input.GetAxis ("Vertical") * transform.forward;

//movement.movementDirection = direction.normalized;


// GetComponent<Rigidbody> ().AddForce (direction.normalized * walkSpeed, ForceMode.Acceleration);


transform.position = transform.position +?

walkSpeed * direction * Time.deltaTime ;

WalkForward ();

return;


if (bWalking) {

bWalking = Walking ();

} else {

}

}


public void WalkTo (Vector3 pos, bool withClickEffect = true)

{


if ((this.transform.position - pos).magnitude < 0.001f) {

return;

}


Vector3[] corners = CalcPathCorners (this.transform.position, pos);


if (corners.Length >= 2) {

bWalking = true;

mPath = corners;

bWalking = true;

// Animation anim = GetComponent<Animation> ();

// anim.CrossFade ("run_forward", 0.3f);

mPathIndex = 0;

transform.position = mPath [0];

if (mClickEffect != null && withClickEffect) {

mClickEffect.SetActive (true);

pos.y += 0.5f;

mClickEffect.transform.position = pos;

Invoke ("HideClickEffect", 1.5f);

}

}

}


private void HideClickEffect ()

{

if (mClickEffect != null) {

mClickEffect.SetActive (false);

}

}


private bool Walking ()

{

bool re = true;


Vector3 curSegSrc = mPath [mPathIndex];

Vector3 curSegDst = mPath [mPathIndex + 1];

Vector3 curPos = transform.position;


Vector3 normalDir = (curSegDst - curSegSrc);

normalDir.Normalize ();


curPos += (normalDir * walkSpeed * Time.deltaTime);


float over = (curPos - curSegSrc).magnitude - (curSegDst - curSegSrc).magnitude;

if (over > 0) {

mPathIndex ++;

if (mPathIndex > mPath.Length - 2) {

curPos = mPath [mPath.Length - 1];

transform.position = curPos;

re = false;

Animation anim = GetComponent<Animation> ();

// anim.CrossFade ("idle", 0.3f);

} else {

curSegSrc = mPath [mPathIndex];

curSegDst = mPath [mPathIndex + 1];

normalDir = (curSegDst - curSegSrc);

normalDir.Normalize ();

curPos = curSegSrc + normalDir * over;


transform.position = curPos;

}

} else {

transform.position = curPos;

}

return re;

}



Vector3[] CalcPathCorners (Vector3 src, Vector3 dst)

{

Vector3[] corners = null;

NavMeshPath path = new NavMeshPath ();

//if (NavMesh.CalculatePath(src, dst, -1, path)){

if (false) {

corners = path.corners;

} else {

corners = new Vector3[2]{src, dst};

}

return corners;

}


void WalkForward()

{

transform.position = transform.position + walkSpeed * transform.forward * Time.deltaTime ;

}

}


正在回答

2 回答

不好意思,看錯了。這個是error。

如果已在Inspector中設(shè)置了Camera的Player,可void Start ()中的效果相同的

“GameObject.Find ("Main Camera").GetComponent<SceneCamera> ().player = this.gameObject;”可以直接刪除掉。

如果想在腳本中設(shè)置Camera跟隨Player的效果,親測了兩個方法:

(1)將“GameObject.Find ("Main Camera").GetComponent<SceneCamera> ().player = this.gameObject;”移至void Awake()方法中

(2)將“GameObject.Find ("Main Camera").GetComponent<SceneCamera> ().player = this.gameObject;”分解成

“GameObject MainCamera;

MainCamera=GameObject.Find("Main Camera");

MainCamera.getComponent<SceneCamera>().player=this.gameObject;

個人推測原因:某處用到了還未來得及初始化的對象,與實現(xiàn)函數(shù)的時間順序有關(guān)。


方法原理:

(1)Awake()是場景啟動時,MonoBehavior創(chuàng)建后,立刻調(diào)用的函數(shù),所以不會產(chǎn)生來不及設(shè)置實例對象的情

況。

(2)= =咳咳,不知道為什么這樣就行地通了,麻煩知道的人告知一下。


若解釋的不對,希望能指出。謝謝


0 回復(fù) 有任何疑惑可以回復(fù)我~

這個只是因程序未完善出現(xiàn)的Warning,不影響運行,可以忽略

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

提示Object reference not set to an instance of an object。未將對象引用設(shè)置到對象的實例 怎么搞啊

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號