I want to insert the stop code into this code. But I could not do it. How can I turn off the isKinematic feature of isKinematicStop object?
I get this Error:
I get this error UnassignedReferenceException: The variable
isKnematickstop of ObstacleController has not been assigned. You
probably need to assign the isKinematickstop variable to the
ObstacleController script in the inspector.
UnityEngine.GameObject.GetComponent [Rigidbody2D] () (at C:
/buildslave/unity/build/artifacts/generated/common/runtime/G??ameObjectBindings.ge??n.cs:35)
ObstacleController.OnCollisionEnter2D (UnityEngine.Collision2D col)
(at Assets / esplades / Scripts / ObstacleController.cs: 52)
Original Script.
using UnityEngine;
using System.Collections;
public class ObstacleController : MonoBehaviour
{
public float hitPushBack;
public GameObject hitEffect;
public Sprite[] sprites;
public void Awake()
{
if (sprites.Length > 0)
GetComponent<SpriteRenderer>().sprite = sprites[Random.Range(0, sprites.Length)];
}
void OnEnable()
{
GameManager.GameStateChanged += OnGameStateChanged;
}
private void OnGameStateChanged(GameState newState, GameState oldState)
{
if (newState == GameState.GameOver)
gameObject.SetActive(false);
}
void OnDisable()
{
GameManager.GameStateChanged -= OnGameStateChanged;
}
void Update()
{
//Quaternion targetRotation = Quaternion.Euler(0, 0, RotationVariables.direction * Mathf.Abs(RotationVariables.maxAngle));
//transform.root.rotation = Quaternion.RotateTowards(transform.root.rotation, targetRotation, RotationVariables.rotationDelta);
}
public void OnCollisionEnter2D(Collision2D col)
{
if (col.collider.tag == "Player")
{
hitEffect.transform.position = col.contacts[0].point;
hitEffect.gameObject.SetActive(true);
GameManager.Instance.playerController.anim.Squeeze();
GameManager.Instance.playerRigidbody.AddForce(col.contacts[0].normal * hitPushBack);
}
}
}
(Col.collider.tag == "Player") in isKinematickstop.GetComponent (). IsKinematic = false; How can I run it?
I did it..
using UnityEngine;
using System.Collections;
public class ObstacleController : MonoBehaviour
{
public float hitPushBack;
public GameObject hitEffect;
public Sprite[] sprites;
//------------------------------------------
public GameObject isKinematickstop;
//------------------------------------------
public void Awake()
{
if (sprites.Length > 0)
GetComponent<SpriteRenderer>().sprite = sprites[Random.Range(0, sprites.Length)];
}
void OnEnable()
{
GameManager.GameStateChanged += OnGameStateChanged;
}
private void OnGameStateChanged(GameState newState, GameState oldState)
{
if (newState == GameState.GameOver)
gameObject.SetActive(false);
}
void OnDisable()
{
GameManager.GameStateChanged -= OnGameStateChanged;
}
void Update()
{
//Quaternion targetRotation = Quaternion.Euler(0, 0, RotationVariables.direction * Mathf.Abs(RotationVariables.maxAngle));
//transform.root.rotation = Quaternion.RotateTowards(transform.root.rotation, targetRotation, RotationVariables.rotationDelta);
}
public void OnCollisionEnter2D(Collision2D col)
{
if (col.collider.tag == "Player")
{
hitEffect.transform.position = col.contacts[0].point;
hitEffect.gameObject.SetActive(true);
GameManager.Instance.playerController.anim.Squeeze();
//------------------------------------------
isKinematickstop.GetComponent<Rigidbody2D>().isKinematic= false;
//------------------------------------------
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…