I have made several stealth type scripts and I am converting them into Custom Actions. I have been successful but I have a question:
Where should I place in the script the assignment variables for instance I have the following:
playerTarget = GameObject.FindGameObjectWithTag("Player");
myRenderer = enemy.GetComponent<Renderer > ();
anim = enemy.GetComponent<Animation > ();
either inside a Start() or Awake() or directly inside the public override float Run() ?
I noticed that inside Start() or Awake() they are not recognized only when I place them inside the Rum() what is the best procedure please?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Placing in Run will be OK, but there is a dedicated AssignValues function that is called before this. Just place your assign code in a function like:
public override AssignValues ()
{
// Your code here
}
Most of AC's "official" Actions demonstrate this use.
it yields an error apparently it requires the return so:
public override void AssignValues
works!!
Yes I have seen this feature in other official Actions but not so clearly and simple as stated by you above.
Thanks again . Perhaps the most salient point about your package is your unbelievable fast response to questions that users have this is rarely found with other suppliers of goodies !!
I give up. I have problems converting to Custom List and spent 8 hours on it.
I wrote a script that checks distance between player and enemy and if DistanceB4Look is met then Enemy turns to LookAt player and if the distance is less than attack distance the enemy walks towards the player. It works like a charm when I attach the script to the enemy AI but I cannot make it work the same way when I use the converted script to a Custom Action. Here is the script inside the Custom Action
public override float Run()
{
PlayerDistance = Vector3.Distance (playerTarget.transform.position, enemy.transform.position);
if (PlayerDistance < DistanceB4Look ) {
anim.CrossFade ("soldierWalk");
enemy.transform.position += enemy.transform.forward * enemySpeed * Time.deltaTime;
}
if (PlayerDistance < DistanceB4Attack)
{
quaternion .... typical and it works
}
return 0f;
}
where
It looks like the code you want to run wants to be called every frame (hence the Time.deltaTime). That kind of function is not appropriate for Actions.
What are you trying to achieve, exactly, by converting your old script into an Action? It might be better to simply use an Action to tell your old script to run.
You are right it was a case of hardheadedness from my part since the stand alone script is working fine. Now I know that there are restrictions in using Custom Actions such as you mention here.
Most of the stealth situations I have used scripts such as laser fence, moving walls, turrets and this last one to check if the player can be seen.
.... I will continue having fun which at my age is a big plus !!