Habr
β
How to become an author
My feed
All streams
Development
Admin
Design
Management
Marketing
PopSci
Search
Write a publication
Settings
Login
Pull to refresh
0
@artemymazurenko
read-only
User
Send message
Profile
Comments
1
Bookmarks
Copy RSS link
Основы создания 2D персонажа в Unity 3D 4.3. Часть 2: бегущий персонаж
artemymazurenko
May 27 2016 at 17:18
using UnityEngine;
using System.Collections;
public class CharacterControllerScript: MonoBehaviour
{
public float maxSpeed = 10f;
private bool isFacingRight = true;
private Animator anim;
/// ///
private void Start()
{
anim = GetComponent();
}
/// /// FixedUpdate
/// Animate Physics = true
///
private void FixedUpdate()
{
float move = Input.GetAxis(«Horizontal»);
anim.SetFloat(«Speed», Mathf.Abs(move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && !isFacingRight)
Flip();
else if (move < 0 && isFacingRight)
Flip();
}
/// ///
private void Flip()
{
isFacingRight = !isFacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Всё сделал. Но не работает. Работаю в Unity3D 5 и не знаю что делать.
Information
Rating
Does not participate
Registered
May 27 2016
Activity
May 27 2016 at 17:16
using System.Collections;
public class CharacterControllerScript: MonoBehaviour
{
public float maxSpeed = 10f;
private bool isFacingRight = true;
private Animator anim;
/// ///
private void Start()
{
anim = GetComponent();
}
/// /// FixedUpdate
/// Animate Physics = true
///
private void FixedUpdate()
{
float move = Input.GetAxis(«Horizontal»);
anim.SetFloat(«Speed», Mathf.Abs(move));
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
if (move > 0 && !isFacingRight)
Flip();
else if (move < 0 && isFacingRight)
Flip();
}
/// ///
private void Flip()
{
isFacingRight = !isFacingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Всё сделал. Но не работает. Работаю в Unity3D 5 и не знаю что делать.