Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do I scale a sprite?

Discussion in 'Scripting' started by Bigmancozmo, Sep 27, 2020.

  1. Bigmancozmo

    Bigmancozmo

    Joined:
    Sep 13, 2020
    Posts:
    17
    I need help scaling a sprite with C# but i don't know how.
    Here is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class BossControl : MonoBehaviour
    7. {
    8. // Start is called before the first frame update
    9. void Start()
    10. {
    11.    
    12. }
    13.  
    14. // Update is called once per frame
    15. void Update()
    16. {
    17.  
    18. }
    19. }
    20.  
    Can someone please adjust my code so it waits 0.5 seconds in the start loop and then changes the size from 1 to 2? (On every axis)
    Everything i try doesn't work
    My sprite i want to change is called "Angry" (a boss form) and it is in a scene called "SampleScene" (default scene name)
     
    Last edited: Sep 27, 2020
  2. Damast

    Damast

    Joined:
    Apr 25, 2019
    Posts:
    13
    For a delayed action have a Look at enumerators:

    IEnumerator wait()
    {
    yield return new waitforsceconds(0.5f)
    gameObject.transform.localScale = new Vector3(2,2,2);
    }

    Start the IEnumerator in the start Methode with StartCouroutine(wait());
     
  3. Bigmancozmo

    Bigmancozmo

    Joined:
    Sep 13, 2020
    Posts:
    17
    It says "waitforseconds" and "StartCoroutine" can't be found
    Why is that happening?
    Also where do i define the IEnumerator method?