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 unity_McDQyp7qhCTdXw · Aug 25, 2020 at 10:56 PM · unity 2dscriptable objectgamedesign

Scriptable object not referencing speed but references damage...

So I have 2 variable of Speed and Damage in a scriptable object.

Here is the code for the first section :-

 [CreateAssetMenu(fileName = "BulletData", menuName = "Data/Bullet")]
 public class BulletDataScriptableObject : ScriptableObject
 {
     public float speed = 5f;
     public int damage = 30;
 } 
 

I then have a prefab object referencing this to fire a 'FireBall' which is utilising the following code :-

 > using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class PlayerProjectiles : MonoBehaviour
 {
     public Animator animator;
     public BulletDataScriptableObject bulletData;
     public float speed;
     public int damage;
     public Rigidbody2D rb;
     public GameObject FireEmbers;
     public float liveTime = 1f;
     
     void Start()
     {
         
         rb.velocity = transform.right * speed;
         speed = bulletData.speed;
         damage = bulletData.damage;
     }
 
     void OnTriggerEnter2D(Collider2D hitInfo)
 
     {
         Enemy enemy = hitInfo.GetComponent<Enemy>();
         if (enemy != null)
         {
             enemy.TakeDamage(damage);
         }
 
         Destroy(gameObject);
         Instantiate(FireEmbers, transform.position, Quaternion.identity);
 
     }
 
     void Update()
     {
         liveTime -= Time.deltaTime;
         if (liveTime <= 0)
         {
             Destroy(this.gameObject);
             Instantiate(FireEmbers, transform.position, Quaternion.identity);
         }
     }
 }


Here's the problem. For some reason my fireball will reference the damage variable but not the speed so when I fire the fireball it doesn't go anywhere unless I manually enter the speed variable in the Unity inspector, damage however it references fine and if I stand point blank at an enemy the fireball will damage them at the right amount. My item power-ups also damage them at the amended power level so I am confused as to why it's not referencing the speed variable.

@Aviryx If you can help again then I officially owe you a beer or something!

Comment
Add comment · Show 4
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 Llama_w_2Ls · Aug 25, 2020 at 11:01 PM 0
Share

I think its referencing the speed variable but its not adding it to your rigidbody. In the start method, its setting rb.velocity to transform.right speed; when it should be transform.right * speed; Let me know if this was a typo or an actual syntax error

avatar image unity_McDQyp7qhCTdXw Llama_w_2Ls · Aug 25, 2020 at 11:09 PM 0
Share

It actually is transform.right * speed, the format of the post was screwed up so I've amended it so it should be more legible now. I'm hoping you can find another issue because it's baffling the crap out of me!

avatar image revolute unity_McDQyp7qhCTdXw · Aug 26, 2020 at 03:19 AM 3
Share
 rb.velocity = transform.right * speed;
 speed = bulletData.speed;

Are you positive that you want to assign rb.velocity with speed before you setup speed variable with bulletData.speed?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by unity_McDQyp7qhCTdXw · Aug 26, 2020 at 09:42 AM

It was indeed the order of the code. Thanks everyone! :)

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

140 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Tilemaps - Create Multiple Levels 0 Answers

2D GAME (non UI object) for every pc resolution 0 Answers

How can I instantiate a gameobject facing another gameobject 2D? 0 Answers

App gets stuck on WebGL 0 Answers

Hello! Was wondering how do I make an object move randomly around the screen. And if it disappears at one side of the screen, it'll appear on the other side. 2 Answers


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