Search Unity

【Unity・C#】 DoTween does not work

Discussion in 'Animation' started by MUU_unity, Feb 29, 2020.

  1. MUU_unity

    MUU_unity

    Joined:
    Apr 16, 2017
    Posts:
    8
    Hello.

    ##Things I want to solve
    I am creating a tap game in Unity with reference to the book. When you tap an object using the asset [DoTween] Implemented to add the score by moving the curve. But when you tap the image, The orb is generated, but it does not move up the screen. The score is not added. [DoTween] Why does not work If you know, please answer.


    Here is the code

    OrbManagar.cs

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using UnityEngine.UI;
    6.  
    7. using DG.Tweening;
    8.  
    9. public class OrbManager : MonoBehaviour {
    10.  
    11.     private GameObject gameManager;
    12.     public Sprite[] orbPicture = new Sprite [3];
    13.  
    14.     public enum ORB_KIND{  
    15.         BLUE,
    16.         GREEN,
    17.         PURPLE,
    18.     }
    19.     private ORB_KIND orbKind;
    20.  
    21.     // Start is called before the first frame update
    22.     void Start() {
    23.         gameManager = GameObject.Find ("GameManager");
    24.     }
    25.  
    26.     // Update is called once per frame
    27.     void Update () {
    28.     }
    29.  
    30.     public void FlyOrb () {
    31.         RectTransform rect = GetComponent<RectTransform> ();
    32.  
    33.         Vector3[] path = {
    34.             new Vector3(rect.localPosition.x * 4.0f, 1100f, 0f),
    35.             new Vector3(0f, 1400f, 0f),
    36.         };
    37.  
    38.         rect.DOLocalPath (path, 0.5f, PathType.CatmullRom)
    39.             .SetEase (Ease.OutQuad)
    40.             .OnComplete (AddOrbPoint);
    41.         rect.DOScale (
    42.             new Vector3 (0.5f, 0.5f, 0f),
    43.             0.5f
    44.         );
    45.     }
    46.        
    47.     void AddOrbPoint () {
    48.         switch (orbKind) {
    49.         case ORB_KIND.BLUE:
    50.             gameManager.GetComponent<GameManager> ().GetOrb (1);
    51.             break;
    52.         case ORB_KIND.GREEN:
    53.             gameManager.GetComponent<GameManager> ().GetOrb (5);
    54.             break;
    55.         case ORB_KIND.PURPLE:
    56.             gameManager.GetComponent<GameManager> ().GetOrb (10);
    57.             break;
    58.         }
    59.  
    60.         Destroy (this.gameObject);
    61.     }
    62.  
    63.     public void SetKind (ORB_KIND kind){
    64.         orbKind = kind;
    65.  
    66.         switch (orbKind) {
    67.         case ORB_KIND.BLUE:
    68.             GetComponent<Image> ().sprite = orbPicture [0];
    69.             break;
    70.         case ORB_KIND.GREEN:
    71.             GetComponent<Image> ().sprite = orbPicture [1];
    72.             break;
    73.         case ORB_KIND.PURPLE:
    74.             GetComponent<Image> ().sprite = orbPicture [2];
    75.             break;        
    76.         }
    77.     }
    78. }
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570