Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    1

    2D Shooter tutorial help!

    Hey there, I've been following the 2D shooter tutorial, and now I'm a bit stuck.

    I keep getting compiling error CS0122, and I'm not sure what is causing it!

    If anyone can help I'd be most grateful.

    Here is the code, the error comes up at enemy.SetPositionAndSpeed ();
    Code:
    using UnityEngine;
    using System.Collections;
    
    public class Bullet : MonoBehaviour {
    	
    	
    	public float ProjectileSpeed;
    	public GameObject ExplosionPrefab;
    	private Transform myTransform;
    		
    	// Use this for initialization
    	void Start () 
    	{
    		myTransform = transform;
    	}
    	
    	// Update is called once per frame
    	void Update () 
    	{
    		float amtToMove = ProjectileSpeed * Time.deltaTime;
    		
    		myTransform.Translate (Vector3.right * amtToMove);
    		
    		if (myTransform.position.x > 9.0f)
    			Destroy(this.gameObject);
    		
    	}
    	
    	void OnTriggerEnter (Collider otherObject)
    	{
    		if (otherObject.tag == "enemy")
    		{	
    			Enemy enemy = (Enemy)otherObject.gameObject.GetComponent ("Enemy");
    			Instantiate (ExplosionPrefab, enemy.transform.position, enemy.transform.rotation);
    			enemy.SetPositionAndSpeed ();
    		
    			Destroy (gameObject);
    		}
    	}
    }

  2. #2
    Join Date
    Oct 2009
    Location
    The In Between. US
    Posts
    2,030
    its been a long time since I did that one so I am just looking from my code to yours and I only really see

    Code:
    myTransform.Translate (Vector3.right * amtToMove);
    
    where mine shows 
    myTransform.Translate (Vector3.up * amtToMove);
    but I can't see why right to up should make a difference.
    it may be coming from somewhere else.
    post the rest of the code its not to much

    EDIT: I just noticed as well under that your "MyTransform.position is .x and mine is .y
    Last edited by elevating; 03-12-2012 at 02:25 PM.
    elevating to new levels of knowledge (that's the plan at least )

  3. #3
    Join Date
    Aug 2007
    Location
    Montreal, Canada
    Posts
    618
    I don't see what is wrong, it might help to include your Enemy script as well
    since that is where you said the error is coming from.

    Also I am not a fan of leaving a space between your function name and first
    opening bracket such as:

    Update ()

    as opposed to

    Update()

    but to the compiler it does not matter.

  4. #4
    Join Date
    Dec 2011
    Posts
    3
    The only thing i can think of is, when you created your Tag for the Enemy object did you name the Tag as "enemy" or "Enemy (without quotes). That could be an issue, or as stealthcoder said, show us ur Enemy script. The problem may reside there as well.

  5. #5
    Join Date
    Mar 2012
    Posts
    1
    The Compiler Error CS0122 means that a member is inaccessible due to its protection level (no I don't memorize these things, I just asked Google.) So my guess is that your SetPositionAndSpeed() method is private instead of public. Set it to public and that error should be resolved.

    --Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •