Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Collider and Script issue

Discussion in 'Scripting' started by Jeriko2k3, Apr 1, 2015.

  1. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    Hello and thanks in advance.

    I am trying to program a scene that when the player collides with an object, the object is then picked up and begins to rotate around the player in a circular pattern around the different vertices. If anyone can point me in the correct direction I would be very much appreciative and send you lots of cookies.

    So far I've managed to just have the player destroy the object (by making it disappear), and I get the following error.

    UnassignedReferenceException: The variable b of _x has not been assigned.
    You probably need to assign the debris variable of the _x script in the inspector.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class _x : MonoBehaviour
    5.  
    6.  
    7. {
    8.  
    9.     public float speed;
    10.     public GameObject b;
    11.     public Vector3 bValues;
    12.    
    13.  
    14.    
    15.  
    16.     void FixedUpdate ()
    17.     {
    18.         float moveHorizontal = Input.GetAxis ("Horizontal");
    19.         float moveVertical = Input.GetAxis ("Vertical");
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
    23.     }
    24.    
    25.  
    26.     void OnTriggerEnter(Collider other)
    27.  
    28.     {
    29.         if (other.gameObject.tag == "x")
    30.          
    31.         {  
    32.          
    33.             other.gameObject.SetActive(false);
    34.                        
    35.          
    36.         }
    37.  
    38.             while  (false);
    39.        
    40.  
    41.         {
    42.             Vector3 bPosition = new Vector3 (Random.Range (-bValues.x, bValues.x), Random.Range (-bValues.y, bValues.y), Random.Range (-bValues.z, bValues.z));
    43.             Quaternion bRotation = Quaternion.identity;
    44.             Instantiate (b, bPosition, bRotation);
    45.          
    46.         }
    47.      
    48.     }
    49.  
    50. }
     
  2. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    I guess I should more accurately state, I am trying to get an object to orbit the player. But I am wanting first to collide with object than transform it into an orbit status.