Наследование: MonoBehaviour
Пример #1
0
    public void PlayInstrument()
    {
        var controller = GetComponentInParent <BeatController>();

        if (!controller.onBeat() || lastHit == controller.hit_count || dead)
        {
            return;
        }
        lastHit          = controller.hit_count;
        audioSource.mute = false;
        spriteSwapper    = GetComponent <SpriteSwapper>();
        GetComponent <SpriteSwapper>().isPlaying = true;

        GameObject obj = Resources.Load <GameObject>("InstrumentEffect");

        //obj = Instantiate(obj, transform.position, Quaternion.identity);
        obj = Instantiate(obj, transform);
        obj.transform.localPosition = Vector3.zero;
        InstrumentEffect instrumentEffect = obj.AddComponent <InstrumentEffect>();

        instrumentEffect.SetSize(3f);  // TODO: Change size based on something
        instrumentEffect.owner          = this;
        instrumentEffect.counteredEnemy = counteredEnemy;
        instrumentEffect.SetColor(instrumentColor);
        Debug.Log(instrumentEffect.GetComponent <SpriteRenderer>().color);
    }
Пример #2
0
 static public int SwapSprite(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         SpriteSwapper self = (SpriteSwapper)checkSelf(l);
         self.SwapSprite();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Пример #3
0
 void Start()
 {
     swapper    = GetComponentInChildren <SpriteSwapper>();
     tr         = transform;
     rb         = GetComponent <Rigidbody2D>();
     timeToDrop = Random.Range(dropInterval * 0.5f, dropInterval * 1.5f);
     NextDecision();
 }
Пример #4
0
 private void Start()
 {
     m_spriteSwapper = GetComponent <SpriteSwapper>();
     m_on            = PlayerPrefs.GetInt("music_on") == 1;
     if (!m_on)
     {
         m_spriteSwapper.SwapSprite();
     }
 }
Пример #5
0
    private void Start()
    {
        this.gameController = GameObject.FindWithTag("GameController").GetComponent <GameController>();
        this.gameController.OnCheckpointChanged += this.LevelCheckpointChanged;

        this.audioSource = this.GetComponent <AudioSource>();
        this.swapper     = this.GetComponent <SpriteSwapper>();

        this.GetComponent <Collider2D>().isTrigger = true;
    }
Пример #6
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        SpriteSwapper spriteSwapper = (SpriteSwapper)target;

        MultiObjectEditorGUI.ObjectField(serializedObject, "HighlightedSprite", "Highlighted Sprite", typeof(Sprite), true);
        MultiObjectEditorGUI.ObjectField(serializedObject, "PressedSprite", "Pressed Sprite", typeof(Sprite), true);
        MultiObjectEditorGUI.ObjectField(serializedObject, "DisabledSprite", "Disabled Sprite", typeof(Sprite), true);
        serializedObject.ApplyModifiedProperties();
    }
    // Update is called once per frame
    void Update()
    {
        Debug.Log("EXEC");
        Debug.Log(execution_rotation);
        //Debug.Log(Quaternion.AngleAxis(-90, Vector3.up).y);
        //Debug.Log(transform.rotation.y);

        if (check && transform.rotation.y < Quaternion.AngleAxis(-90, Vector3.up).y) //We are checking the Y-componet of rotation
        {
            //IMPORTANT: According to rspeed, if too fast, it will not activate the IF statement and will fail
            //to swap the sprite. A good value for rspeed is 1 and below since it runs throught most rotation values
            //but there are still instances where it fails.

            //To fix this, we will add an additional check that checks if the sprite is the same or not after certain point
            //Ensuring this IF executes only once

            //When we have rotated to the point you can only see the edge of the card
            //then we swap the sprites
            SpriteSwapper myInstance = gameObject.GetComponent <SpriteSwapper>(); //Make instance of attached script

            myInstance.SwapSprite();                                              //Call function belonging to script
            Debug.Log("SWAPPED MADE ONCE ONLY");

            //Hmmm if we want this to happen only once, why dont we just destroy this script?
            //So that the if is not being checked everything during the update! HUH!
            //Destroy(this); //by "this" we mean ---> REMOVE THIS SCRIPT

            //Damn....now, the script gets removed before we complete the entire 180 rotation
            check = false; //this way we will never come back here again
        }

        //Debug.Log(transform.rotation);
        Debug.Log("outside");
        transform.rotation = Quaternion.Slerp(transform.rotation, execution_rotation, rspeed * Time.deltaTime); //Rotate a full circle (spin)
        Debug.Log(transform.rotation);
        if (transform.rotation.y == (-1 * execution_rotation.y))
        {
            Debug.Log("FIN");
            Destroy(this); //NOW REMOVE SCRIPT!
        }
    }
Пример #8
0
 // Use this for initialization
 void Start()
 {
     swapper = gameObject.GetComponent <SpriteSwapper> ();
 }
Пример #9
0
 // Start is called before the first frame update
 void Start()
 {
     GetComponent <Rigidbody2D>().freezeRotation = true;
     spriteSwapper = GetComponent <SpriteSwapper>();
     GetComponent <SpriteSwapper>().isPlaying = false;
 }