Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Oct 14, 2015 at 07:02 PM by thorr57 for the following reason:

Altri

avatar image
0
Question by thorr57 · Oct 13, 2015 at 02:27 PM · c#2d gameflyingenergy

I have problem.

When i apply this script

 using UnityEngine;
   using System.Collections;
      
 public class Volo : MonoBehaviour {
    public Vector2 jumpForce = new Vector2(0, 300);
    float flightSpeed = 10.0f; // Set this speed to whatever you want.
    float energyDecay = 1.0f; // Set this to whatever you want.
    float energy;
      const float maxEnergy = 100;
      bool grounded;
      
      void Update ()
      {
           Vector2 jumpForce = new Vector2(0, 300);
          if (Input.GetKeyDown("space") && grounded) // Controls the initial jump
          {
              GetComponent<Rigidbody2D>().velocity = Vector2.zero;
              GetComponent<Rigidbody2D>().AddForce(jumpForce);
          }
      if (Input.GetKey("space") && energy > 0) // Controls flight for as long as space is held down
          {
    Vector2 v = GetComponent<Transform>().velocity; // Creates a temporary velocity variable
    v.y = flightSpeed; // Sets the temporary variables Y velocity to the flightSpeed
     GetComponent<Transform>().velocity = v; // Sets the character velocity to the flightSpeed
   energy -= energyDecay; // Reduces energy by energyDecay every frame
          }
      }
      
      void OnCollisionEnter(Collision col) // When the character collides with something
      {
          if(col.collider.tag == "ground") // If the object has the tag "ground"
          {
              energy = maxEnergy; // Reset energy to max
              grounded = true;
          }
      }
      void OnCollisionExit(Collision col) // When the character stops colliding with something
      {
          if(col.collider.tag == "ground") // If the object has the tag "ground"
          {
              grounded = false;
          }
      }
  }

to the character,when i press play there is another error:Assets/scripts/Volo.cs(24,59): error CS1061: Type UnityEngine.Transform' does not contain a definition forvelocity' and no extension method velocity' of type UnityEngine.Transform'could be found (are you missing a using directive or an assembly reference?)What should i do? I really need it in a few days. thanks in started.

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0

Answer by Dave-Carlile · Oct 13, 2015 at 02:31 PM

If you look at Unity's documentation about the Transform class, you will see that there is indeed no velocity property. What you're most likely looking for would be the Rigidbody or RigidBody2D component. In fact, if you look up in your code a little bit you'll see the velocity being set there on that very component.

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

Follow this Question

Answers Answers and Comments

32 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

Related Questions

Make an energy wich decreases when the character jumps 2 Answers

How to move a bullettrail the direction the player is facing 0 Answers

how create EndLess game Like zombie Tsunami 1 Answer

NullReferenceException: Object reference not set to an instance of an object Groundcheck.OnTriggerEnter2D (UnityEngine.Collider2D col) (at Assets/object/code/Groundcheck.cs:17) 0 Answers

System Equipment and Changing Clothes in 2d Endless Runner Game ? 0 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