Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

FPS Bullet Script

Discussion in 'Scripting' started by ARAKIT, Jan 10, 2018.

  1. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    Hello,

    I am making an FPS shooter game, with a little sphere named Bullet. I want Bullet to go to the current position of the character which is named char_shadow. I tried using this script but it would not work.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class scriptforsphere : MonoBehaviour {
    6.  
    7.     GameObject char_shadow;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.        
    12.     }
    13.    
    14.     float speed;
    15.  
    16.     // Update is called once per frame
    17.     void Update () {
    18.         float step = speed * Time.deltaTime;
    19.         transform.position = Vector3.MoveTowards(transform.position, char_shadow.transform.position, step);
    20.     }
    21. }
     
  2. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    Please Help!
     
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    5,397
    try changing 'float speed' to 'public float speed' and setting a value greater than 0 from the inspector. :)
     
  4. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    helps, but still doesn't work
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    5,397
    Helps? :) before it would have been zero, so never move.
    What is happening? Explain more beyond it doesn't work, please.

    Do you have any errors?
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    4,909
  7. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    5,397
    ah, so it is :)
     
  8. ARAKIT

    ARAKIT

    Joined:
    Sep 23, 2017
    Posts:
    8
    ok, I got it to work, i just needed to make it public
     
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    5,397
    Cool, glad you got it working.