Beispiel #1
0
    public void Break(bool front)
    {
        if (front)
        {
            frontBroken = true;
        }
        else
        {
            backBroken = true;
        }

        // Add extra drag to train
        tc.AddDrag(dragDelta);

        // Spawn interactable w/ particles
        GameObject sparks = Instantiate(sparkPrefab, GameObject.FindGameObjectWithTag("Train").transform);

        sparks.transform.position = transform.position + sparks.transform.localPosition;
        if (!front)
        {
            sparks.transform.position += new Vector3(0, 0, 7.3f);
        }
        WheelInteract wi = sparks.GetComponent <WheelInteract>();

        wi.car     = gameObject.GetComponent <WheelBreak>();
        wi.isFront = front;

        sparks.GetComponent <TTSID>().Init();
        TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(sparks);
        TTS.ObjectSync            os          = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>();
        os.initBuffer.Add(initMessage);

        SyncState();
    }
    public override void AfterUse()
    {
        //spawn food object here
        Debug.Log("Spawn food object");

        GameObject food = Instantiate(foods[Random.Range(0, foods.Length)], gameObject.transform.position + new Vector3(-1, 1.55f, 0), Quaternion.identity);

        food.transform.parent = GameObject.FindGameObjectWithTag("Train").transform;
        food.GetComponent <TTSID>().Init();
        TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(food);
        TTS.ObjectSync            os          = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>();
        os.initBuffer.Add(initMessage);
        inUse = false;
    }
    public override void AfterUse()
    {
        //spawn food object here
        Debug.Log("Spawn coal");
        interactTransform.GetComponent <TTSPlayerAnimator>().SetBool(9, false);
        GameObject coal = Instantiate(coalPrefabs[Random.Range(0, coalPrefabs.Length)], gameObject.transform.position + new Vector3(0, 0.5f, 0), Quaternion.identity);

        coal.transform.parent = GameObject.FindGameObjectWithTag("Train").transform;
        coal.GetComponent <TTSID>().Init();
        TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(coal);
        TTS.ObjectSync            os          = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>();
        os.initBuffer.Add(initMessage);
        inUse = false;
    }
    public override void AfterUse()
    {
        interactTransform.GetComponent <TTSPlayerAnimator>().SetBool(7, false);
        if (interactTransform.GetComponentInChildren <PickupVolume>().potentialPickups.Contains(toCook.transform))
        {
            interactTransform.GetComponentInChildren <PickupVolume>().potentialPickups.Remove(toCook.transform);
        }

        string prefabTag = toCook.transform.GetChild(1).name;

        toCook.GetComponent <TTSID>().Remove();


        GameObject foodPrefab = Resources.Load($"Prefabs/{prefabTag}", typeof(GameObject)) as GameObject;
        GameObject cookedFood = GameObject.Instantiate(foodPrefab, transform.position + Vector3.up * 2, Quaternion.identity, GameObject.FindGameObjectWithTag("Train").transform);

        cookedFood.GetComponent <TTSID>().Init();
        TTS.GameObjectInitMessage initMessage = new TTS.GameObjectInitMessage(cookedFood);
        TTS.ObjectSync            os          = GameObject.FindGameObjectWithTag("Network").GetComponent <TTS.ObjectSync>();
        os.initBuffer.Add(initMessage);

        toCook = null;
        inUse  = false;
    }