Search Unity

how to re-size a sphere using distance?

Discussion in 'Scripting' started by no1yugioh, Jul 28, 2012.

  1. no1yugioh

    no1yugioh

    Joined:
    Jul 24, 2012
    Posts:
    3
    I have made a turret which can only shoot the enemy within certain firing distance.
    Now, I want to indicate the distance using a sphere with transparent color.
    However, I don't know how to create a sphere with a radius. I can't find any function in Unity can do this.:-|
    Anyone done this before??:eek:
     
  2. kablammyman

    kablammyman

    Joined:
    Nov 22, 2010
    Posts:
    507
  3. no1yugioh

    no1yugioh

    Joined:
    Jul 24, 2012
    Posts:
    3
    I know how to change the position but the main problem is how to set the scale to fit the distance.
    Currently, the only way is to find the scale manually by changing the scale and comparing with the distance during the run-time.
     
  4. groovyMyserioso

    groovyMyserioso

    Joined:
    Dec 4, 2012
    Posts:
    2
    Would this work?

    var ourLocation : Vector3;
    var theirLocation : Vector3;
    var scaleAmount : float;

    function Start(){

    theirLocation = GameObject.Find("Main Camera").transform.position;

    }
    function Update(){
    ourLocation = transform.position;
    scaleAmount = Vector3.Distance(ourLocation,theirLocation);
    transform.localScale = Vector3(scaleAmount/10,scaleAmount/10, scaleAmount/10);
    }