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 lorenzo456 · Mar 02, 2012 at 05:26 AM · shootgameplayfireball

Problem with tutorial script

im using the tutorial from the tornado twins but when i put in the script to shoot my fireball (video 5) it wont go to gameplay so i did something wrong but idk what so can someone paste the script for me.

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 FLASHDENMARK · Mar 02, 2012 at 06:25 AM 0
Share

When trying to play the game do you see a red colored error in the left-hand cornor?

avatar image lorenzo456 · Mar 02, 2012 at 07:52 PM 0
Share

yes i do see it

avatar image FLASHDENMARK · Mar 02, 2012 at 08:52 PM 0
Share

That is a error message. It tells you that you have an error in one of the scripts you wrote. Post the script here and we will be able to help you further.

avatar image lorenzo456 · Mar 03, 2012 at 12:10 AM 0
Share

var speed = 3.0; var rotateSpeed = 3.0; var bullitPrefab:Transform;

function Update () { var controller : CharacterController = GetComponent(CharacterController);

 // Rotate around y - axis
 transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

 // $$anonymous$$ove forward / backward
 var forward = transform.TransformDirection(Vector3.forward);
 var curSpeed = speed * Input.GetAxis ("Vertical");
 controller.Simple$$anonymous$$ove(forward * curSpeed);

 if(Input.GetButtonDown(''jump''))
 {
     var bullit = Instantiate(bullitPrefab, GameObject.Find(''spawnpoint'').transform.position, Quaternion.identity);
 }

}

@script RequireComponent(CharacterController)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kleptomaniac · Mar 03, 2012 at 01:07 AM

This code was absolutely full of errors! The compiler will not run if there are errors in a script.

You were using two quotation marks instead of one double quotation mark to define your GetButtonDown and your GameObject.Find. Also, a tip: don't use GameObject.Find in Update(); it is pointlessly expensive. Instead use it in either Awake() or Start() because the GameObject.Find will only need to reference that object in a variable once in order to define it. Here is the reformatted code:

 var speed : float = 3.0;
 var rotateSpeed : float = 3.0;
 var bullitPrefab : Transform;
 private var controller : CharacterController;
 private var spawnPoint : GameObject;
 @script RequireComponent(CharacterController)
 
 function Start () {
 controller = CharacterController = GetComponent(CharacterController);
 spawnPoint = GameObject.Find("spawnpoint");
 }
 
 function Update () {
 // Rotate around y - axis
 transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
 
 // Move forward / backward
 var forward = transform.TransformDirection(Vector3.forward);
 var curSpeed = speed * Input.GetAxis ("Vertical");
 controller.SimpleMove(forward * curSpeed);
 
 if(Input.GetButtonDown("Jump")) {
     var bullit = Instantiate(bullitPrefab, spawnPoint.transform.position, Quaternion.identity);
     }
 }

Good luck, Klep

Edit: Code was edited due to @aldonaletto noticing some errors in my code. See comment below for info. Thanks!

Comment
Add comment · Show 5 · 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 aldonaletto · Mar 03, 2012 at 03:14 AM 0
Share

You should declare the variables controller and spawnPoint outside any function (variables declared inside a function are temporary, and unknown outside). They should also be set in Start, not Awake - Awake is called during the object creation, and the spawn point object may not exist yet.

avatar image Kleptomaniac · Mar 03, 2012 at 04:50 AM 0
Share

Ah O$$anonymous$$, thanks for that. Edited code to reflect this.

avatar image lorenzo456 · Mar 03, 2012 at 11:56 AM 0
Share

thanks guys but now i still get a error at the left bottom of the screen: Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.Js(193,53): UCW0003: WARNING: Bitwise operation 'I' on boolean values won't shortcut. Did you mean 'II'?

and another one that says: Assets/moving.js(9,14): BCE0049: Expression 'CharacterController' cannot be assigned to.

I'm really new to this so I don't know much about scripting and thanks again guys.

avatar image aldonaletto · Mar 04, 2012 at 03:38 PM 0
Share

The line 9 has a typo - it should be:

 controller = GetComponent(CharacterController);

About the other error: what the hell the ThirdPersonController.js is doing in your project? Anyway, you can simply ignore this message - it's just a warning, and will not make any difference in that case.

avatar image lorenzo456 · Mar 04, 2012 at 05:05 PM 0
Share

Thank you so much I am really new to this and never scripted something before thanks for you help and everyone here thanks again now i can continue with the tutorial

avatar image
1

Answer by aldonaletto · Mar 03, 2012 at 03:03 AM

This code has some errors and missing instructions:
- A double quote is the character ", not two single quotes!
- Most functions in Unity are case sensitive, so check if "jump" and "spawnpoint" are correctly written (the standard button name is "Jump").
- You must apply a force or set the rigidbody velocity to make the bullit move - this part of the code is missing.
The fixed code should be:

...
if(Input.GetButtonDown("Jump")) // check the spelling
{
    var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnpoint").transform.position, Quaternion.identity);
    bullit.rigidbody.velocity = forward * 20.0; // set the bullet speed
}
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

7 People are following this question.

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

Related Questions

Bullet not moving 1 Answer

Problem creating a 2D scroller shooting game 2 Answers

Attaching position of an object in game to position of cursor on screen 0 Answers

No Reload Script Works 1 Answer

Disable & Re-enable 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