• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Help me understanding Basic Game Design Please? 2 Answers

When a single renderer.color is changed in a group of objects, change the remaining objects. 2 Answers

Resources.Load for scriptable objects - can it be done? 1 Answer

Scriptable Object storing Instantiated Objects Show Mismatch Types 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