Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Will21 · Nov 27, 2014 at 08:27 PM · poweruppower-up

Help! How can I get my power up script to work?

I am making a retro-like Metroidvania game and am building a test level to test all my power ups, and I am trying to make one that lets the player run faster this is my script so far NOTE: Needs to be in JavaScript : #pragma strict

 var Speed : float = 12;
 
 function Update () 
 {
 
 if (Input.GetKey (KeyCode.Space))  
 {
 transform.Translate(Vector3(0,Speed,0) * Time.deltaTime);
 }
 
 if (Input.GetKey (KeyCode.A)) 
 {transform.localScale.x = 1;
 transform.Translate(Vector3(-Speed,0,0) * Time.deltaTime);
 }
 
 if (Input.GetKey (KeyCode.D)) 
 {
 transform.localScale.x = 1;
 transform.Translate(Vector3(Speed,0,0) * Time.deltaTime);
 }
 
 }
 
  function OnTriggerEnter(other : Collider)
  {
       if(other.tag == "SuperSpeed");
       {
            Destroy(GameObject.FindWithTag ("SuperSpeed"));
            Speed = Speed + 8;
       }
  
  }
 
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image koray1396 · Nov 27, 2014 at 08:56 PM 1
Share

First, you can use code tags to show your code. It is not readable now.

Second, you can use

 Destroy(other.gameObject);
 //ins$$anonymous$$d of below. You already have a reference to "SuperSpeed" object.
 //Destroy(GameObject.FindWithTag ("SuperSpeed"));

your trigger method might not be working, you can test it by putting a debug inside OnTriggerEnter, so you can see at the console that trigger event is working.

 Debug.Log("Trigger Entered");

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bubzy · Nov 27, 2014 at 09:57 PM

yuck, i would write a seperate script for the powerup and have an "effect" on it

(im not going to apologise for using c# because imo its better :P)

like

 using UnityEngine;
 using System.Collections;
 
 public class bonusPickup : MonoBehaviour {
 
     // Use this for initialization
 
     public float speedBonus;
     public float healthBonus;
     public float jumpBonus;
 
     void Start () {
     //this can be a speedBoost although i would usually make prefabs for each one instead of coding
     //that way you can make something like smallBoost = 4 bigBoost = 8 or whatever
     speedBonus = 8f;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }


and then on the player

 using UnityEngine;
 using System.Collections;
 
 public class playerScript : MonoBehaviour {
 
     // Use this for initialization
     private float speed = 2f;
     private float health = 100f;
     private float jumpHeight = 1f;
 
 
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnCollisionEnter(Collision collision)
     {
         if(collision.gameObject.tag == "powerup")
         {
             bonusPickup tempPowerup;
             tempPowerup = collision.gameObject.GetComponent<bonusPickup>();
             speed += tempPowerup.speedBonus;
             health += tempPowerup.healthBonus;
             jumpHeight += tempPowerup.jumpBonus;
                     Destroy(collision.gameObject);
         }
     }
 }
 

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Powerup Script to make player invincible? 1 Answer

How can i fix this error? 2 Answers

NullReferenceException: I think unity bug 3 Answers

Animation for Powerup Won't Work? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges