C# 有没有一个简单的方法来制作2d unity游戏的动作脚本?
我需要你的帮助。我对C#相当了解,但不知道C#UnityEngine名称空间 Unity不支持足够的运动脚本,因为我不知道如何使用C#for Unity,所以我不想尝试编辑主代码 任何使用此命名空间的代码我都会感到困惑:C# 有没有一个简单的方法来制作2d unity游戏的动作脚本?,c#,unity3d-2dtools,C#,Unity3d 2dtools,我需要你的帮助。我对C#相当了解,但不知道C#UnityEngine名称空间 Unity不支持足够的运动脚本,因为我不知道如何使用C#for Unity,所以我不想尝试编辑主代码 任何使用此命名空间的代码我都会感到困惑: 使用UnityEngine; 我对这样的变量感到困惑: 公共浮动速度=6.0F; 公共浮子跳跃速度=8.0F; 公共浮子重力=20.0F; 专用矢量3移动方向=矢量3.0; 这是一个简单的2d角色移动控制器。要使此脚本正常工作,您必须: 1。将此脚本分配给角色 public
使用UnityEngine;
我对这样的变量感到困惑:
公共浮动速度=6.0F;
公共浮子跳跃速度=8.0F;
公共浮子重力=20.0F;
专用矢量3移动方向=矢量3.0;
这是一个简单的2d角色移动控制器。要使此脚本正常工作,您必须:
1。将此脚本分配给角色
public float speed;
public float jumpHeight;
Rigidbody2D rb;
void Start(){
//Get the rigidbody2d of the gameObject this script is assigned to.
rb = GetComponent<Rigidbody2D>();
}
void Update() {
//Determine the direction of the movement based on user input.
float moveDir = Input.GetAxis("Horizontal");
//Calculate the velocity of the gameObject.
rb.velocity = new Vector2(moveDir * speed, rb.velocity.y);
// Your jump code:
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
}
2。向角色添加刚体2D
public float speed;
public float jumpHeight;
Rigidbody2D rb;
void Start(){
//Get the rigidbody2d of the gameObject this script is assigned to.
rb = GetComponent<Rigidbody2D>();
}
void Update() {
//Determine the direction of the movement based on user input.
float moveDir = Input.GetAxis("Horizontal");
//Calculate the velocity of the gameObject.
rb.velocity = new Vector2(moveDir * speed, rb.velocity.y);
// Your jump code:
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
}
3。从角色的检查器中为speed和jumpHeight变量指定一个值
public float speed;
public float jumpHeight;
Rigidbody2D rb;
void Start(){
//Get the rigidbody2d of the gameObject this script is assigned to.
rb = GetComponent<Rigidbody2D>();
}
void Update() {
//Determine the direction of the movement based on user input.
float moveDir = Input.GetAxis("Horizontal");
//Calculate the velocity of the gameObject.
rb.velocity = new Vector2(moveDir * speed, rb.velocity.y);
// Your jump code:
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
}
公共浮动速度;
公众浮标高度;
刚体2d rb;
void Start(){
//获取此脚本分配给的游戏对象的RigidBy2D。
rb=GetComponent();
}
无效更新(){
//根据用户输入确定移动方向。
float moveDir=Input.GetAxis(“水平”);
//计算游戏对象的速度。
rb.velocity=新矢量2(moveDir*速度,rb.velocity.y);
//您的跳转代码:
if(Input.GetKeyDown(KeyCode.Space))
{
rb.velocity=新矢量2(rb.velocity.x,跳跃高度);
}
}
希望这对你有用。如果您需要更多帮助,请查看unity官方网站。这是一个简单的2d角色移动控制器。要使此脚本正常工作,您必须: 1。将此脚本分配给角色
public float speed;
public float jumpHeight;
Rigidbody2D rb;
void Start(){
//Get the rigidbody2d of the gameObject this script is assigned to.
rb = GetComponent<Rigidbody2D>();
}
void Update() {
//Determine the direction of the movement based on user input.
float moveDir = Input.GetAxis("Horizontal");
//Calculate the velocity of the gameObject.
rb.velocity = new Vector2(moveDir * speed, rb.velocity.y);
// Your jump code:
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
}
2。向角色添加刚体2D
public float speed;
public float jumpHeight;
Rigidbody2D rb;
void Start(){
//Get the rigidbody2d of the gameObject this script is assigned to.
rb = GetComponent<Rigidbody2D>();
}
void Update() {
//Determine the direction of the movement based on user input.
float moveDir = Input.GetAxis("Horizontal");
//Calculate the velocity of the gameObject.
rb.velocity = new Vector2(moveDir * speed, rb.velocity.y);
// Your jump code:
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
}
3。从角色的检查器中为speed和jumpHeight变量指定一个值
public float speed;
public float jumpHeight;
Rigidbody2D rb;
void Start(){
//Get the rigidbody2d of the gameObject this script is assigned to.
rb = GetComponent<Rigidbody2D>();
}
void Update() {
//Determine the direction of the movement based on user input.
float moveDir = Input.GetAxis("Horizontal");
//Calculate the velocity of the gameObject.
rb.velocity = new Vector2(moveDir * speed, rb.velocity.y);
// Your jump code:
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
}
}
公共浮动速度;
公众浮标高度;
刚体2d rb;
void Start(){
//获取此脚本分配给的游戏对象的RigidBy2D。
rb=GetComponent();
}
无效更新(){
//根据用户输入确定移动方向。
float moveDir=Input.GetAxis(“水平”);
//计算游戏对象的速度。
rb.velocity=新矢量2(moveDir*速度,rb.velocity.y);
//您的跳转代码:
if(Input.GetKeyDown(KeyCode.Space))
{
rb.velocity=新矢量2(rb.velocity.x,跳跃高度);
}
}
希望这对你有用。如果您需要更多帮助,请联系unity官方