Topic: Toggle Script in Character Prefab

I would like to turn on/off a script from a character prefab programmatically for particular moves. However, when I try to access the script from battlegui.cs:

player.gameObject.GetComponent<>("abc");

I get an error that the name does not exist in the current context. How could I add the script so it is accessible in battlegui.cs?

Thanks

Share

Thumbs up Thumbs down

Re: Toggle Script in Character Prefab

You can easily create you own custom script to handle whatever you need to.

This example should help

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UFE3D;

public class NewBehaviourScript1 : MonoBehaviour
{
    private ControlsScript myControlsScript;

    // Start is called before the first frame update
    void Start()
    {
        if (myControlsScript == null)
        {
            myControlsScript = GetComponentInParent<ControlsScript>();
        }       
    }

    // Update is called once per frame
    void Update()
    {
        CheckMove();   
    }

    private void CheckMove()
    {
        if (myControlsScript == null
            || myControlsScript.currentMove == null) return;

        if (myControlsScript.currentMove.moveName == "Special Move")
        {
            // Do something.
        }
    }
}

Share

Thumbs up +1 Thumbs down