New User: Help understand Click to View Object Script..

Hi, I’m a very new user. I’m beta testing a course on learning Unity 3d from Coursera.

The project of the first section is to build a solar system. Setting up primatives, putting a map on them, making them rotate and orbit, have sounds as they swoop past the camera…simple stuff… I’ve got that working just fine.

An additional script in the program (well two). A “Look at target” script on the camera and a “Change Look At Target” placed on the planets so you can switch which planet the main camera is looking at. I’ve got this working just fine.

Well, I wanted to get fancy. I do 3d art with Daz Studio, so I have lots of additional assets…so I imported an OBJ of the TARDIS and the Enterprise.

And I have both of them flying around the sun or planets, looking and behaving how I want.
EXCEPT, the “Change Look At Target” script doesn’t work on them. I put the script on them (they show up in the Hierarchy as a group of parented parts…I’ve tried the script on each of the parts…but not all at once…) but clicking on them doesn’t change the camera.

I’ve read the script, and don’t see anything that would say “This only works on sphere primatives”. Because it’s a beta test class, there’s no active teachers to answer the question, so I’ve come here :slight_smile:

Here’s the script:

using UnityEngine;
using System.Collections;

public class ChangeLookAtTarget : MonoBehaviour {

    public GameObject target; // the target that the camera should look at

    void Start() {
        if (target == null)
        {
            target = this.gameObject;
            Debug.Log ("ChangeLookAtTarget target not specified. Defaulting to parent GameObject");
        }
    }

    // Called when MouseDown on this gameObject
    void OnMouseDown () {
        // change the target of the LookAtTarget script to be this gameobject.
        LookAtTarget.target = target;
        Camera.main.fieldOfView = 60*target.transform.localScale.x;
    }
}

Can anyone offer any thoughts on why what I’ve tried doesn’t work?

Have you tried a breakpoint on the line in your mouse down to see if it is detecting the enterprise at all?
I’m not real good at getting mouse controls to work but see if the things that currently work have colliders & if they do check to see if yours have them. It could be something as simple as that (hopefully).

Thanks for your reply…but when I said i was new…I meant it… what I described is the sole amount I know about any of this :confused:
I did not put “colliders” on the planets…so I don’t think there’d be any on there.

If you click on the planet or anything else the camera can focus on look in the inspector where all the things like transform, scale etc are & see if there is any mention of a collider

Ah, I see.
And yep, the planets have a sphere colider on it.
And because Unity is (so far) so intuitive to use, I added component, found collider choices under physics, tried a sphere and mesh which didn’t work*, then tried cube, and it worked, if hard to click on… so seeing the nice “edit” button, I took the small box next to the enterprise and doing my best Trelane impression, I put the cube surrounding the Enterprise, and now it works just as it should!.
And the TARDIS being a box, was even easier to do!

Thanks so much for you help! I’ve now learned something, so today hasn’t been all bad :slight_smile:

(* I bet if I went back and looked at the sphere and mesh colliders, now understaning “edit”, I’d get those going too :slight_smile: )

Excellent, have fun :slight_smile: