Hi
I have been working on a custom script for a moving platform and i had it working in Unity 4.6 but now i have updated to Unity 5 i get one error on line 121. Any ideas why?
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
// Action made by NickCoxMedia
// Moving Platform Transition Ping Pong
// __ECO__ __PLAYMAKER__ __ACTION__
using UnityEngine;
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("This will transform a object from one position to another with the option to pause. A ping pong like motion.")]
public class MovingPlatform : FsmStateAction
{
[RequiredField]
[Tooltip("Game Object to move")]
public FsmOwnerDefault gameObject; //owner
[RequiredField]
[Tooltip("Choose a starting point")]
public FsmOwnerDefault StartingPoint;
[RequiredField]
[Tooltip("Choose a destination point")]
public FsmOwnerDefault DestinationPoint;
[Tooltip("How fast the platform moves. Use decimal places to slow down further e.g. 0.02")]
public FsmFloat Speed;
[Tooltip("How long to delay before moving")]
public FsmFloat delayBeforeMoving;
[Tooltip("shows when the platform returns")]
private FsmBool Switch = false;
private FsmFloat pauseTime;
private bool arrivedAtOurDestination = false;
public PlayMakerActionsUtils.EveryFrameUpdateSelector updateType;
public override void Reset()
{
gameObject = null;
DestinationPoint = null;
StartingPoint = null;
Switch = false;
delayBeforeMoving = 3f;
pauseTime = 0f;
Speed = 1f;
updateType = PlayMakerActionsUtils.EveryFrameUpdateSelector.OnUpdate;
}
public override void Awake()
{
if (updateType == PlayMakerActionsUtils.EveryFrameUpdateSelector.OnFixedUpdate)
{
Fsm.HandleFixedUpdate = true;
}
}
public override void OnUpdate()
{
if (updateType == PlayMakerActionsUtils.EveryFrameUpdateSelector.OnUpdate)
{
DoMovingPlatform();
}
}
public override void OnLateUpdate()
{
if (updateType == PlayMakerActionsUtils.EveryFrameUpdateSelector.OnLateUpdate)
{
DoMovingPlatform();
}
}
public override void OnFixedUpdate()
{
if (updateType == PlayMakerActionsUtils.EveryFrameUpdateSelector.OnFixedUpdate)
{
DoMovingPlatform();
}
}
void DoMovingPlatform()
{
var owner = Fsm.GetOwnerDefaultTarget(gameObject); //get owner
var destination = Fsm.GetOwnerDefaultTarget(DestinationPoint); //get destination
var origin = Fsm.GetOwnerDefaultTarget(StartingPoint); //get StartingPoint
if (owner != null && destination != null && origin != null)
{
// If it's at the destination spot, it sets Switch to true.
if((owner.transform.position == destination.transform.position) && !arrivedAtOurDestination)
{
Switch = true;
pauseTime = Time.time + delayBeforeMoving.Value;
arrivedAtOurDestination = true;
}
// If it's at the origin spot, it sets Switch to false.
if((owner.transform.position == origin.transform.position) && !arrivedAtOurDestination)
{
Switch = false;
pauseTime = Time.time + delayBeforeMoving.Value;
arrivedAtOurDestination = true;
}
// If Switch becomes true, it tells the platform to move to its Origin.
if(Switch.Value && (Time.time > pauseTime.Value))
{
owner.transform.position = Vector3.MoveTowards(owner.transform.position, origin.transform.position, Time.deltaTime * Speed.Value); //use delta time so time scale works
arrivedAtOurDestination = false;
}
else if (Time.time > pauseTime.Value)
{
// If Switch is false, it tells the platform to move to the destination.
owner.transform.position = Vector3.MoveTowards(owner.transform.position, destination.transform.position, Time.deltaTime * Speed.Value); //use delta time so time scale works
arrivedAtOurDestination = false;
}
}
}
}
}
errors in unity
NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.Actions.MovingPlatform.DoMovingPlatform () (at Assets/PlayMaker Custom Actions/Transform/MovingPlatform.cs:121)
HutongGames.PlayMaker.Actions.MovingPlatform.OnFixedUpdate () (at Assets/PlayMaker Custom Actions/Transform/MovingPlatform.cs:83)
HutongGames.PlayMaker.FsmState.OnFixedUpdate () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:237)
HutongGames.PlayMaker.Fsm.FixedUpdateState (HutongGames.PlayMaker.FsmState state) (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2496)
HutongGames.PlayMaker.Fsm.FixedUpdate () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1831)
PlayMakerFixedUpdate.FixedUpdate () (at c:/Users/Alex/Documents/Unity/Playmaker/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFixedUpdate.cs:17)