// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { GameObject prefab = behaviorTreeExecutor.GetGameObjectVariable(prefabID); if (prefab == null) { return(Result.Failure); } GameObject spawnedObject; if (spawnAsChild) { spawnedObject = Instantiate(prefab, behaviorTreeExecutor.transform); } else { spawnedObject = Instantiate(prefab, behaviorTreeExecutor.transform.TransformPoint(prefab.transform.position), prefab.transform.rotation); } if (storeInVariable) { TypedVariable <GameObject> gameObjectVariableOverride = behaviorTreeExecutor.variableOverrides.GameObjects.Find(x => x.id == spawnedObjectID); if (gameObjectVariableOverride == null) { UnityEngine.Debug.LogWarning("Object ID " + spawnedObjectID + " not found in variable overrides of " + behaviorTreeExecutor.name); } else { gameObjectVariableOverride.value = spawnedObject; } } return(Result.Success); }
// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { GameObject gameObject = behaviorTreeExecutor.GetGameObjectVariable(objectID); if (gameObject == null) { return(Result.Failure); } if (delay > 0) { Destroy(gameObject, delay); } else { Destroy(gameObject); } return(Result.Success); }
// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { TypedVariable <GameObject> objectVariable = behaviorTreeExecutor.variableOverrides.GameObjects.Find(x => x.id == objectID); if (objectVariable == null) { return(Result.Failure); } GameObject objectToApplyForceTo = objectVariable.value; if (objectToApplyForceTo == null) { UnityEngine.Debug.LogError("No object to apply a force to", behaviorTreeExecutor); return(Result.Failure); } Rigidbody rigidbody = objectToApplyForceTo.GetComponent <Rigidbody>(); if (rigidbody == null) { UnityEngine.Debug.LogError("Provided prefab object of " + name + " in behavior tree of " + behaviorTreeExecutor.name + " has no rigidbody."); return(Result.Failure); } switch (relativeObject) { default: case RelativeObjectOption.None: rigidbody.AddForce(force, forceMode); break; case RelativeObjectOption.Self: rigidbody.AddForce( behaviorTreeExecutor.transform.TransformVector(force), forceMode); break; case RelativeObjectOption.Other: rigidbody.AddForce( behaviorTreeExecutor.GetGameObjectVariable(otherObjectID).transform.TransformVector(force), forceMode); break; } return(Result.Success); }
// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { GameObject obj = behaviorTreeExecutor.GetGameObjectVariable(objectID); if (obj == null) { return(Result.Failure); } Vector3 lookTarget = obj.transform.position; if (stayUpright) { lookTarget.y = behaviorTreeExecutor.transform.position.y; } behaviorTreeExecutor.transform.LookAt(lookTarget); return(Result.Success); }
// This is called when the node is updated public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor) { if (agent == null) { agent = behaviorTreeExecutor.GetComponent <NavMeshAgent>(); if (agent == null) { UnityEngine.Debug.LogError(behaviorTreeExecutor.name + " has no NavMeshAgent component assigned but " + name + " is trying to access it.", behaviorTreeExecutor); return(Result.Failure); } } GameObject target = behaviorTreeExecutor.GetGameObjectVariable(targetID); if (target == null) { UnityEngine.Debug.LogError("Did not find target object with id " + targetID + " for " + GetType(), behaviorTreeExecutor); return(Result.Failure); } agent.SetDestination(target.transform.position); return(Result.Success); }