Search Unity

how to return object to start of game

Discussion in 'Scripting' started by josecleudo4, Aug 16, 2019.

  1. josecleudo4

    josecleudo4

    Joined:
    Aug 10, 2019
    Posts:
    2
    My Object starts on the top monitor screen, it is falling and with each click it changes sprites, I am using this script

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. public class  Teste : MonoBehaviour
    5. {
    6.     public Animator anim;
    7.  
    8.    
    9.     public KeyCode attack1;
    10.  
    11.     public Transform spell;
    12.    
    13.    
    14.     void Start()
    15.     {
    16.        
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update()
    21.     {
    22.  
    23.    
    24.        
    25.     }
    26.  
    27.     void shootNow() {
    28.    
    29.     Instantiate (spell, new Vector3 (1, .75f, 0), spell.rotation);
    30. }
    31.  
    32.     void OnMouseDown() {
    33.  
    34.     anim.SetTrigger ("heroAttack");
    35. }
    36. }
    37.  

    when the object makes its last animation I want it to come back from where it started, remembering that my object is falling.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Just record its current position in Start to a variable, and when you want to return it to that position you set transform.position to that original stored position.