I have successfully imported Unity Standard Assets cross-platform input
In imported cross-platform script, UnityStandardAssets.CrossCrossPlatformInput works fine
but when I use it in a CharacterController2D script that does not respond, it shows errors
unknown package is actually a namespace in c #
and the path to the file for standard assets is Assets \ Standard Assets \ CrossPlatformInput \ Scripts
and CharacterController2D path is Assets \ Scripts
following script CharacterController2D
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityStandardAssets.CrossCrossPlatformInput;
public class CharacterController2D : MonoBehaviour {
[Range(0.0f, 10.0f)]
public float moveSpeed = 3f;
public float jumpForce = 600f;
public int playerHealth = 1;
public LayerMask whatIsGround;
public Transform groundCheck;
[HideInInspector]
public bool playerCanMove = true;
public AudioClip coinSFX;
public AudioClip deathSFX;
public AudioClip fallSFX;
public AudioClip jumpSFX;
public AudioClip victorySFX;
Transform _transform;
Rigidbody2D _rigidbody;
Animator _animator;
AudioSource _audio;
float _vx;
float _vy;
bool facingRight = true;
bool isGrounded = false;
bool isRunning = false;
bool canDoubleJump = false;
int _playerLayer;
int _platformLayer;
void Awake () {
_transform = GetComponent<Transform> ();
_rigidbody = GetComponent<Rigidbody2D> ();
if (_rigidbody==null)
Debug.LogError("Rigidbody2D component missing from this gameobject");
_animator = GetComponent<Animator>();
if (_animator==null)
Debug.LogError("Animator component missing from this gameobject");
_audio = GetComponent<AudioSource> ();
if (_audio==null) {
Debug.LogWarning("AudioSource component missing from this gameobject. Adding one.");
_audio = gameObject.AddComponent<AudioSource>();
}
_playerLayer = this.gameObject.layer;
_platformLayer = LayerMask.NameToLayer("Platform");
}
void Update()
{
if (!playerCanMove || (Time.timeScale == 0f))
return;
_vx = CrossPlatformInputManager.GetAxisRaw ("Horizontal");
if (_vx != 0)
{
isRunning = true;
} else {
isRunning = false;
}
_animator.SetBool("Running", isRunning);
_vy = _rigidbody.velocity.y;
isGrounded = Physics2D.Linecast(_transform.position, groundCheck.position, whatIsGround);
if (isGrounded)
{
canDoubleJump = true;
}
_animator.SetBool("Grounded", isGrounded);
if(isGrounded && CrossPlatformInputManager.GetButtonDown("Jump"))
{
doJump ();
}
else if(canDoubleJump && CrossPlatformInputManager.GetButtonDown("Jump"))
{
doJump ();
canDoubleJump = false;
}
if(CrossPlatformInputManager.GetButtonUp("Jump") && _vy>0f)
{
_vy = 0f;
}
_rigidbody.velocity = new Vector2(_vx * moveSpeed, _vy);
Physics2D.IgnoreLayerCollision(_playerLayer, _platformLayer, (_vy > 0.0f));
}
void LateUpdate()
{
Vector3 localScale = _transform.localScale;
if (_vx > 0)
{
facingRight = true;
} else if (_vx < 0) {
facingRight = false;
}
if (((facingRight) && (localScale.x<0)) || ((!facingRight) && (localScale.x>0))) {
localScale.x *= -1;
}
_transform.localScale = localScale;
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag=="MovingPlatform")
{
this.transform.parent = other.transform;
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.tag=="MovingPlatform")
{
this.transform.parent = null;
}
}
void FreezeMotion() {
playerCanMove = false;
_rigidbody.isKinematic = true;
}
void UnFreezeMotion() {
playerCanMove = true;
_rigidbody.isKinematic = false;
}
void PlaySound(AudioClip clip)
{
_audio.PlayOneShot(clip);
}
public void ApplyDamage (int damage) {
if (playerCanMove) {
playerHealth -= damage;
if (playerHealth <= 0) {
PlaySound(deathSFX);
StartCoroutine (KillPlayer ());
}
}
}
public void doJump()
{
_vy = 0f;
_rigidbody.AddForce (new Vector2 (0, jumpForce));
PlaySound(jumpSFX);
}
public void EnemyJump()
{
doJump ();
}
public void FallDeath () {
if (playerCanMove) {
playerHealth = 0;
PlaySound(fallSFX);
StartCoroutine (KillPlayer ());
}
}
IEnumerator KillPlayer()
{
if (playerCanMove)
{
FreezeMotion();
_animator.SetTrigger("Death");
yield return new WaitForSeconds(2.0f);
if (GameManager.gm)
GameManager.gm.ResetGame();
else
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
public void CollectCoin(int amount) {
PlaySound(coinSFX);
if (GameManager.gm)
GameManager.gm.AddPoints(amount);
}
public void Victory() {
PlaySound(victorySFX);
FreezeMotion ();
_animator.SetTrigger("Victory");
if (GameManager.gm)
GameManager.gm.LevelCompete();
}
public void Respawn(Vector3 spawnloc) {
UnFreezeMotion();
playerHealth = 1;
_transform.parent = null;
_transform.position = spawnloc;
_animator.SetTrigger("Respawn");
}
}
I used cross-platform input for the first time, so I donβt even know why this error shows