Hey folks, I am making a game where the main character can encounter bushes and branches. I intended to start an animation of these branches that makes them wave during an encounter with the player. I now have 2 scripts. one attached to the branch and one on the polygon collider which is on the branch. I am asking this question because I wasn’t able to find this problem in #C
The branch scripts looks like this:
using UnityEngine;
using System.Collections;
public class MovingBranch: MonoBehaviour {
public bool PlayAnimation = false;
void Start () {
}
void Update () {
if(PlayAnimation){
// Whatever function or code you write to start the animation
// or however you want to do the animation}
}
}
}
And the script attached on the polygon collider looks like this:
using UnityEngine;
using System.Collections;
public class Box: MonoBehaviour {
// Make sure you have the Branch Object
public GameObject Branch;
// The Script of the Branch;
private MovingBranch movingbranch;
void Start () {
// This will get the script and set the trainscript
movingbranch= Branch.GetComponent("MovingBranch") as MovingBranch ;
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider collision){
if(collision.gameObject.tag == "Player"){
movingbranch.PlayAnimation = true;
}
}
}
I converted a existing script into my project but it simply doesn’t work even though there are no errors.
I don’t know why the animation is not started when being touched by the main player? I am a beginner in scripting.
If somebody can point me into the right direction that would be really helpful