NullReferenceException:对象引用未设置为对象PlayerMovement.Update的实例

问题描述

import re

with open("file.txt","r") as file:
    for line in file:
        line = line.rstrip()
        if line:
            if not re.match(r'\s*#',line):
                file.write(line)

为什么我会收到此错误? 我正在使用unity5.3 这是完整的错误

NullReferenceException:对象引用未设置为对象的实例 PlayerMovement.Update()(位于Assets / Scripts / PlayerMovement.cs:16)

解决方法

controllerdirection未初始化。确保它们在您拨打Update()之前。