C#脚本

①Button调用动画:

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

public class AssemblyController : MonoBehaviour 
{
    bool p1 = false;
    bool p2 = false;
    bool p3 = false;
    
    void Start () 
    {
        
    }
    
    void Update () 
    {
        GameObject MSixteen1 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N(01)");
        Animator animC1 = MSixteen1.GetComponent<Animator>();
        animC1.enabled = p1;

        GameObject MSixteen2 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (02)");
        Animator animC2 = MSixteen2.GetComponent<Animator>();
        animC2.enabled = p1;

        GameObject MSixteen3 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (03)");
        Animator animC3 = MSixteen3.GetComponent<Animator>();
        animC3.enabled = p1;

        GameObject MSixteen4 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (04)");
        Animator animC4 = MSixteen4.GetComponent<Animator>();
        animC4.enabled = p1;

        GameObject MSixteen5 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (05)");
        Animator animC5 = MSixteen5.GetComponent<Animator>();
        animC5.enabled = p1;

        GameObject MSixteen6 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (06)");
        Animator animC6 = MSixteen6.GetComponent<Animator>();
        animC6.enabled = p1;

        GameObject MSixteen7 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (07)");
        Animator animC7 = MSixteen7.GetComponent<Animator>();
        animC7.enabled = p1;

        GameObject MSixteen8 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (08)");
        Animator animC8 = MSixteen8.GetComponent<Animator>();
        animC8.enabled = p1;

        GameObject MSixteen9 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (09)");
        Animator animC9 = MSixteen9.GetComponent<Animator>();
        animC9.enabled = p1;

        GameObject MSixteen10 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N (10)");
        Animator animC10 = MSixteen10.GetComponent<Animator>();
        animC10.enabled = p1;


        GameObject MTwelve1 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N(01)");
        Animator animB1 = MTwelve1.GetComponent<Animator>();
        animB1.enabled = p2;

        GameObject MTwelve2 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (02)");
        Animator animB2 = MTwelve2.GetComponent<Animator>();
        animB2.enabled = p2;

        GameObject MTwelve3 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (03)");
        Animator animB3 = MTwelve3.GetComponent<Animator>();
        animB3.enabled = p2;

        GameObject MTwelve4 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (04)");
        Animator animB4 = MTwelve4.GetComponent<Animator>();
        animB4.enabled = p2;

        GameObject MTwelve5 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (05)");
        Animator animB5 = MTwelve5.GetComponent<Animator>();
        animB5.enabled = p2;

        GameObject MTwelve6 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (06)");
        Animator animB6 = MTwelve6.GetComponent<Animator>();
        animB6.enabled = p2;

        GameObject MTwelve7 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (07)");
        Animator animB7 = MTwelve7.GetComponent<Animator>();
        animB7.enabled = p2;

        GameObject MTwelve8 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (08)");
        Animator animB8 = MTwelve8.GetComponent<Animator>();
        animB8.enabled = p2;

        GameObject MTwelve9 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (09)");
        Animator animB9 = MTwelve9.GetComponent<Animator>();
        animB9.enabled = p2;

        GameObject MTwelve10 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M12X100-N (10)");
        Animator animB10 = MTwelve10.GetComponent<Animator>();
        animB10.enabled = p2;


        GameObject MEight1 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N(01)");
        Animator animA1 = MEight1.GetComponent<Animator>();
        animA1.enabled = p3;

        GameObject MEight2 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (02)");
        Animator animA2 = MEight2.GetComponent<Animator>();
        animA2.enabled = p3;

        GameObject MEight3 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (03)");
        Animator animA3 = MEight3.GetComponent<Animator>();
        animA3.enabled = p3;

        GameObject MEight4 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (04)");
        Animator animA4 = MEight4.GetComponent<Animator>();
        animA4.enabled = p3;

        GameObject MEight5 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (05)");
        Animator animA5 = MEight5.GetComponent<Animator>();
        animA5.enabled = p3;

        GameObject MEight6 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (06)");
        Animator animA6 = MEight6.GetComponent<Animator>();
        animA6.enabled = p3;

        GameObject MEight7 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (07)");
        Animator animA7 = MEight7.GetComponent<Animator>();
        animA7.enabled = p3;

        GameObject MEight8 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (08)");
        Animator animA8 = MEight8.GetComponent<Animator>();
        animA8.enabled = p3;

        GameObject MEight9 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (09)");
        Animator animA9 = MEight9.GetComponent<Animator>();
        animA9.enabled = p3;

        GameObject MEight10 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M8X80-N (10)");
        Animator animA10 = MEight10.GetComponent<Animator>();
        animA10.enabled = p3;
    }

    public void OnAButtonClick()
    {
        p3 = !p3;
    }

    public void OnBButtonClick()
    {
        p2 = !p2;
    }


    public void OnCButtonClick()
    {
        p1 = !p1;
    }
}

②控制物体出现:

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

public class ShowPrefabs : MonoBehaviour
{
    public GameObject tishiPrefab;

    public Vector3 a = Vector3.zero;
    public Quaternion b = new Quaternion(0, 0, 0, 0);


    // Use this for initialization
    void Start ()
    {

    }
    
    // Update is called once per frame
    void Update ()
    {
        a.x =0;
        a.y = -0.69f;
        a.z = 0;
        if (Input.GetKeyDown(KeyCode.Q))
        {
            GameObject go = GameObject.Instantiate(tishiPrefab, a, b) as GameObject;
        }
    }
}

③动画演示

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

public class Controller : MonoBehaviour
{
        bool p1 = false;

    public GameObject tishiPrefab;
    public Vector3 a = Vector3.zero;
    public Quaternion b = new Quaternion(0, 0, 0, 0);

    void Start()
    {

    }
        void Update()
    {
        GameObject MSixteen1 = GameObject.Find("GB_FASTENER_BOLT_DESB15 A M16X100-N");
        Animator animC1 = MSixteen1.GetComponent<Animator>();
        animC1.enabled = p1;
    }

    public void OnAButtonClick()
    {
        GameObject go = GameObject.Instantiate(tishiPrefab, a, b) as GameObject;
        p1 =!p1;
    }
}

④颜色闪烁

shake += Time.deltaTime;  
       
 if (shake % 1 > 0.5f)
      
 {     
    this.GetComponent<MeshRenderer>().material.color = Color.blue;  
 } 
    
  else
    
 {            
    this.GetComponent<MeshRenderer>().material.color = Color.red;      
 }  

猜你喜欢

转载自blog.csdn.net/KillMeHealMe/article/details/82802113