Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(196评价)
价格: 4039.00元
学习老师的UGUI课程的时候
徐牧知发起了问答2017-09-11
5
回复
702
浏览

添加了这个脚本后

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using UnityEngine.EventSystems;

 

public class MyScoll : MonoBehaviour,IBeginDragHandler,IEndDragHandler {

private ScrollRect scrollRect;

private float[] pageArray = new float[]{0,0.333f,0.666f,1};

// Use this for initialization

void Start () {

scrollRect = GetComponent<ScrollRect> ();

}

// Update is called once per frame

void Update () {

}

public void OnBeginDrag(PointerEventData eventData){

}

public void OnEndDrag(PointerEventData eventData){

float posX = scrollRect.horizontalNormalizedPosition;

print (posX);

int index = 0;

float offset = Mathf.Abs (pageArray [index] - posX);

for (int i = 0 ; i< pageArray.Length ; i++){

float offsetTemp = Mathf.Abs (pageArray [i] - posX);

if (offsetTemp < offset) {

index = i;

offset = offsetTemp;

}

}

}

}

UNITY 报错,提示

NullReferenceException: (null)
UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/artifacts/generated/common/editor/SerializedPropertyBindings.gen.cs:87)
UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:193)
UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:185)
UnityEditor.MaterialEditor.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:1773)

点击后无法定位到是哪行代码出错

所有回复
  • siki 2017-09-12

    NullReferenceException: (null)
    UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/artifacts/generated/common/editor/SerializedPropertyBindings.gen.cs:87)
    UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:193)
    UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:185)
    UnityEditor.MaterialEditor.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:1773)

    这个错误提示并没有指定我们代码的错误行数在哪里,都是一些unity自己内置的代码的问题,这个错误信息是完整的吗

     

     

    还有-5条回复,点击查看
    你还没有登录,请先登录注册
  • 徐牧知 2017-09-12

    是完整的,这个问题很奇怪,这个错误不影响代码逻辑,但是每次执行的时候都会报这个错误

    还有-2条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!