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

Need help coding a powerup script

Discussion in 'Scripting' started by Jeebus6969, Jun 23, 2021.

  1. Jeebus6969

    Jeebus6969

    Joined:
    Apr 19, 2021
    Posts:
    4
    So I'm trying to make a powerup that when picked up changes the sprite for the weapon currently being used to the new weapon/powerup

    I currently have this for my powerup script -
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Microsoft.Unity.VisualStudio;

    public class PowerUp : MonoBehaviour
    {
    public GameObject pickupEffect;
    //public class PowerUpEffect Ability;
    void OnTriggerEnter2D (Collider2D other)
    {
    if (other.CompareTag("Player"))
    {
    Pickup(other);
    }
    }

    public void Pickup(Collider2D player)
    {
    Instantiate(pickupEffect, transform.position, transform.rotation);

    //PowerAbility();

    Destroy(gameObject);
    }

    public void PowerAbility(Collider2D other)
    {
    if (other.CompareTag("Player"))
    {

    }
    }

    }
     
  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
  3. Jeebus6969

    Jeebus6969

    Joined:
    Apr 19, 2021
    Posts:
    4
    So I'm trying to make a powerup, so when picked up changes the weapon currently being used to the new weapon/powerup but don't know how to code that
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,762
    Before you learn how to code that, please learn how to tag code:

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    You might have a lot of luck with googling for this:

    Screen Shot 2021-06-22 at 10.21.16 PM.png
     
  5. Jeebus6969

    Jeebus6969

    Joined:
    Apr 19, 2021
    Posts:
    4
    alright thanks I will try that