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

Does Anyone Know How To Fix This?

Discussion in 'Scripting' started by Real_BTN4, Nov 6, 2020.

  1. Real_BTN4

    Real_BTN4

    Joined:
    Oct 16, 2020
    Posts:
    23
    Does anyone know how to fix this script? I'm trying to make it so that when the player runs into the GameObject called "Blank" It will destroy itself, freeze the player for 10 seconds, and make the FireGuardian play his Cutscene Animation



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class BlankMovement : MonoBehaviour
    8. {
    9.  
    10. public GameObject FireGuardian;
    11. public GameObject Blank;
    12. public Animation Cutscene;
    13.  
    14. void Start()
    15. {
    16.     FireGuardian.GetComponent<Animation>();
    17. }
    18.     Vector2 movement;
    19.  
    20.     private void OnCollisionEnter2D(Collision2D other)
    21.     {
    22.         if (other.gameObject.tag == "player")
    23.         {
    24.            
    25.             FireGuardian.Play("Cutscene");
    26.  
    27.         }
    28.     }
    29.  
    30.     // Update is called once per frame
    31.  
    32. }
    33.  
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Is this the correct script to fix? I don't see any code that is supposed to do what you say it should be doing other than the playing of the cutscene.
     
  3. alexeu

    alexeu

    Joined:
    Jan 24, 2016
    Posts:
    257
    Vector2 movement; is out of a method...
     
    MlleBun likes this.
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    That's not the issue - it's just a global field in this case. The script will compile just fine.

    Edit: Actually, there is something else that will make it fail to compile:
    Code (CSharp):
    1. FireGuardian.Play("Cutscene");
    FireGuardian is a GameObject type, and there's no such "Play" method defined for a GameObject.
     
    Last edited: Nov 6, 2020
    Joe-Censored likes this.
  5. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    That script will play an animation named 'Cutscene' if the object the script is attached to collides with a collider who's object has the tag "player".
    It does not use Vector2 movement, it does not use GameObject blank, it does not destroy anything, it won't freeze anything. Note that you must have a game object wired up up FireGuardian, and that object must have an Animation component attached.

    There is currently nothing to fix in the script - you simply have no code to do the things you want (freeze and destroy)
     
    Joe-Censored likes this.
  6. Real_BTN4

    Real_BTN4

    Joined:
    Oct 16, 2020
    Posts:
    23
    Do you know how to make another GameObject play an animation with a script?