- Home /
Question by
ykchris2002 · Feb 22, 2019 at 09:19 AM ·
sendmessage
send message
I want to finish ScriptA to the last SendMessage to ScriptB by the head once, should I write it?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class StaticObjectsGenerator2 : ObjectGenerator { public GameObject[] Transforms; public GameObject Egg1; public DuckBrust DuckBrust; int currentObjIndex = 0;
private void Start()
{
MaxGenerationNumber = Transforms.Length;
Egg1 = GameObject.FindGameObjectWithTag("cube");
}
public override void RecieveData(ImageData recievedData)
{
if (recievedData != null && recievedData.name == Name)
{
base.RecieveData(recievedData);
GameObject obj = GeneratedObjects[GeneratedObjects.Count - 1];
obj.transform.position = Transforms[currentObjIndex].transform.position;
obj.transform.rotation = Transforms[currentObjIndex].transform.rotation;
obj.transform.localScale = Transforms[currentObjIndex].transform.lossyScale;
currentObjIndex++;
currentObjIndex %= Transforms.Length;
}
//#if UNITY_EDITOR
if (recievedData == null)
{
base.RecieveData(recievedData);
GameObject obj = GeneratedObjects[GeneratedObjects.Count - 1];
obj.transform.position = Transforms[currentObjIndex].transform.position;
obj.transform.rotation = Transforms[currentObjIndex].transform.rotation;
obj.transform.localScale = Transforms[currentObjIndex].transform.lossyScale;
currentObjIndex++;
currentObjIndex %= Transforms.Length;
}
//#endif
}
public override void Update()
{
if (Input.GetKeyDown(KeyCode.Delete))
{
foreach (GameObject obj in GeneratedObjects)
{
Destroy(obj);
}
GeneratedObjects.Clear();
currentObjIndex = 0;
}
}
public void LateUpdate()
{
Egg1.SendMessage("SKYCHRIS");
}
}
using System.Collections.Generic; using UnityEngine;
public class DuckBrust : MonoBehaviour {
public GameObject Duck;
public GameObject Egg1;
public DuckMove duckmove_script;
Animator anim;
public void Start()
{
//Egg1 = GameObject.FindGameObjectWithTag("Egg")
if (Duck == null)
Duck = GameObject.FindGameObjectWithTag("Player");
if (duckmove_script == null)
duckmove_script = Duck.GetComponent<DuckMove>();
anim = GetComponent<Animator>();
StartCoroutine(Run());
}
public IEnumerator Run()
{
anim.SetBool("Burst", false);
duckmove_script.enabled = false;
yield return new WaitForSeconds(2);
anim.SetBool("Burst", true);
yield return new WaitForSeconds(3);
duckmove_script.enabled = true;
yield return new WaitForSeconds(3);
Egg1.gameObject.SetActive(false);
}
public void SKYCHRIS()
{
Debug.Log("hihi");
}
}
Comment
Your answer
Follow this Question
Related Questions
Help With Homing Missiles - Annoying! 3 Answers
The function SendMessage in js can not return values? 0 Answers
SendMessage with multiple parameters 3 Answers
SendMessage() to inactive object? 3 Answers