I am trying to call a function to an object by calling the SendMessage function. But it is not working. The first script is like the one below, it is attached to a sphere with rigidbody.
using UnityEngine;
using System.Collections;
public class TouchLogicGravity : TouchLogic {
void Start(){
this.rigidbody.useGravity = false;
}
void OnTouch3D(){
this.rigidbody.useGravity = true;
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "platform") {
other.gameObject.SendMessage("StartFall");
}
}
}`
And the second script where SendMessage is called is like below, it is attached with a cube with rigidbody:
using UnityEngine;
using System.Collections;
public class PlatformFall : MonoBehaviour {
public float startTime,currentTime,elapsedTime;
public bool fall=false;
// Update is called once per frame
void Update () {
if(fall == true){
currentTime = Time.time;
elapsedTime = currentTime - startTime;
if (elapsedTime >= 5) {
timeTrigger();
}
}
}
void StartFall(){
Debug.Log("Start Fall Started Just Now");
startTime = Time.time;
fall = true;
}
void timeTrigger(){
this.gameObject.rigidbody.useGravity = true;
this.gameObject.rigidbody.isKinematic = false;
}
}
I am really perplexed why the SendMessage is not working.