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 juanantoniorosado23 · Apr 22, 2021 at 01:19 PM · gungunfiregun movement

gun shooting script, gun activation script if you help me solve it when i solve it i will post it here so anyone can use it

alt textI had a problem with this script of my game to shoot the pistols and I got this error error CS1525: Invalid expression term can you help me and I tried to solve it but I could not this is the script alt text

disparadorcs-microsoft-visual-studio-22-04-2021-9.png (134.4 kB)
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 juanantoniorosado23 · Apr 22, 2021 at 01:27 PM 0
Share

this is the problematic script

using UnityEngine; using System.Collections;

 public class Disparador : MonoBehaviour
 {
     Rigidbody projectile;
     public int speed = 20; //Velocidad de la bala.
     void Update()
     {
         if (Input.GetButtonDown("Fire1"))//Si se pulsa el boton izquierdo del ratón.
         {
             Rigidbody instantiatedProjectile = Instantiate(
              projectile, transform.position, transform.rotation);
             instantiatedProjectile.velocity =
              transform.TransformDirection(Vector3(0, 0, speed));
             Physics.IgnoreCollision(instantiatedProjectile.GetComponent.< Collider > (),
              transform.root.GetComponent.< Collider > ());
         }
     }
 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Pokedlg3 · Apr 22, 2021 at 01:27 PM

On line 15, you must use the new Vector3(). try changing line 15 to like this:

 instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0,0,speed));

This is because you need to instantiate a new class to set a new value for the vector. indicate that you are calling a constructor and not just any method that returns an object. And serves to prevent an instance with a null attribute from existing.

It turns out that you put a "." after the GetComponent, but you don't need the dot. GetComponent();

try changing like this:

 Physics.IgnoreCollision(instantiatedProjectile.GetComponent< Collider > (),
 transform.root.GetComponent< Collider >());
Comment
Add comment · Show 11 · 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
avatar image juanantoniorosado23 · Apr 22, 2021 at 01:30 PM 0
Share

thank you very much I really appreciate

avatar image Pokedlg3 juanantoniorosado23 · Apr 22, 2021 at 01:32 PM 0
Share

You're welcome :)

avatar image juanantoniorosado23 · Apr 22, 2021 at 01:36 PM 0
Share

You can also write the problematic line of code, please, I don't know which vector 3 is new.

avatar image Pokedlg3 juanantoniorosado23 · Apr 22, 2021 at 01:41 PM 0
Share

Ok will write

avatar image juanantoniorosado23 · Apr 22, 2021 at 01:51 PM 0
Share

using UnityEngine; using System.Collections;

public class Disparador : MonoBehaviour { Rigidbody projectile; public int speed = 20; //Velocidad de la bala. void Update() { if (Input.GetButtonDown("Fire1"))//Si se pulsa el boton izquierdo del ratón. { Rigidbody instantiatedProjectile = Instantiate( projectile, transform.position, transform.rotation); instantiatedProjectile.velocity = instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed)); Physics.IgnoreCollision(instantiatedProjectile.GetComponent.< Collider > (), transform.root.GetComponent.< Collider > ()); } }

} //I still get the error and I have even more and they are error CS1525: //Invalid expression //term //error CS1001: Identifier expected

avatar image Pokedlg3 juanantoniorosado23 · Apr 22, 2021 at 02:04 PM 0
Share

It turns out that you put a "." after the GetComponent, but you don't need the dot. GetComponent();

try changing like this:

 Physics.IgnoreCollision(instantiatedProjectile.GetComponent< Collider > (),
 transform.root.GetComponent< Collider >());
avatar image juanantoniorosado23 Pokedlg3 · Apr 22, 2021 at 02:05 PM 0
Share

Thank you so much

Show more comments

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

116 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

Related Questions

How to make gun sway script affect camera 1 Answer

Make bullet launch at center of screen 2 Answers

How to setup gun shot sound using only animator 0 Answers

Ok i got a script i need help on. 0 Answers

Need help with my gun script! 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