Search Unity

how to instantiate

Discussion in 'Android' started by dr-mad, Jan 4, 2011.

  1. dr-mad

    dr-mad

    Joined:
    Feb 15, 2010
    Posts:
    19
    hi i have a question i get an error if i want to instantiate a rigidbody object just like shooting something

    the bullet i shoot is a rigidbody and i apply force to it but i get errors

    this is the code

    as you can see the bullet1 is a transform variable normaly on the top of the script.

    the spawnPoint1 is in front of my players arm for shooting

    but i get an error on the second line

    this is the error

    BCE0019: 'rigidbody' is not a member of 'UnityEngine.Object'.

    what should i do???
     
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Duck Typing is not supported on mobiles (docs). Use #pragma strict and cast the instantiated object to a resulting type before assigning it to the var Bullet.
     
  3. dr-mad

    dr-mad

    Joined:
    Feb 15, 2010
    Posts:
    19
    hi i figure out how to instantiate but now i want to add force to it but i keep getting that this error


    NullReferenceException: Object reference not set to an instance of an object


    heres my code
    i get the error on the bulletforce.rigidbody


    can someone please help me a bit i keep trying

    it spawns a bullet but the force wont work

    thanks for reading and i hope for a awnser greets dr-mad
     
  4. kagura

    kagura

    Joined:
    Jan 3, 2011
    Posts:
    54
    You must add Physics > Rigidbody to prefab 'bulletPrefabs'